mirror of
https://github.com/tomasriveral/NoteWrapper.git
synced 2026-08-12 02:18:38 +02:00
Backup: Fix (#3) rsync arguments were not stored correcly
This commit is contained in:
+4
-1
@@ -221,11 +221,14 @@ arg_next:
|
|||||||
cJSON *rsyncArgsJSON = cJSON_GetObjectItem(backupJSON, "rsyncArgs");
|
cJSON *rsyncArgsJSON = cJSON_GetObjectItem(backupJSON, "rsyncArgs");
|
||||||
if (rsyncArgsJSON && cJSON_IsArray(rsyncArgsJSON)) { // if it is what we expected
|
if (rsyncArgsJSON && cJSON_IsArray(rsyncArgsJSON)) { // if it is what we expected
|
||||||
rsyncArgsNumber = cJSON_GetArraySize(rsyncArgsJSON);
|
rsyncArgsNumber = cJSON_GetArraySize(rsyncArgsJSON);
|
||||||
|
debug("In %s, rsyncArgsNumber is calculated to %d.", configPath, rsyncArgsNumber);
|
||||||
rsyncArgs = realloc(rsyncArgs, (size_t)rsyncArgsNumber);
|
rsyncArgs = realloc(rsyncArgs, (size_t)rsyncArgsNumber);
|
||||||
|
debug("In %c, rsyncArgs are:", configPath);
|
||||||
for (int i = 0; i < rsyncArgsNumber; i++) {
|
for (int i = 0; i < rsyncArgsNumber; i++) {
|
||||||
cJSON *argJSON = cJSON_GetArrayItem(rsyncArgsJSON, i);
|
cJSON *argJSON = cJSON_GetArrayItem(rsyncArgsJSON, i);
|
||||||
if (argJSON && cJSON_IsString(argJSON)) {
|
if (argJSON && cJSON_IsString(argJSON)) {
|
||||||
rsyncArgs[i] = cJSON_GetStringValue(argJSON);
|
rsyncArgs[i] = strdup(cJSON_GetStringValue(argJSON));
|
||||||
|
altDebug("%s\n", rsyncArgs[i]);
|
||||||
} else {error(1, "user", "One element in rsyncArgs array in %s is not a string", configPath);}
|
} else {error(1, "user", "One element in rsyncArgs array in %s is not a string", configPath);}
|
||||||
}
|
}
|
||||||
} else {error(1, "user", "%s did not contained a rsyncArgs array inside the backup section or the value is from an unexpected type", configPath);}
|
} else {error(1, "user", "%s did not contained a rsyncArgs array inside the backup section or the value is from an unexpected type", configPath);}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ void _error(const int shouldDebug, const int condition, const char *type, const
|
|||||||
|
|
||||||
static void copyDir(const char *source, const char *destination, const char **rsyncArgs, const int rsyncArgsNumber, const int shouldDebug) {
|
static void copyDir(const char *source, const char *destination, const char **rsyncArgs, const int rsyncArgsNumber, const int shouldDebug) {
|
||||||
debug("Backuping... source: %s and destination: %s", source, destination);
|
debug("Backuping... source: %s and destination: %s", source, destination);
|
||||||
|
debug("Rsync has %d extra arguments", rsyncArgsNumber);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
error(pid < 0, "program", "fork() faild. pid = %d", pid);
|
error(pid < 0, "program", "fork() faild. pid = %d", pid);
|
||||||
@@ -87,6 +88,11 @@ static void copyDir(const char *source, const char *destination, const char **rs
|
|||||||
args[i+2] = (char*)source;
|
args[i+2] = (char*)source;
|
||||||
args[i+3] = (char*)destination;
|
args[i+3] = (char*)destination;
|
||||||
args[i+4] = NULL; // execvp expect last arg to be NULL
|
args[i+4] = NULL; // execvp expect last arg to be NULL
|
||||||
|
debug("rsync command:");
|
||||||
|
for (int k = 0; k <= i+4; k++) {
|
||||||
|
altDebug("%s ", args[k]);
|
||||||
|
}
|
||||||
|
altDebug("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
execvp("rsync", args);
|
execvp("rsync", args);
|
||||||
|
|||||||
Reference in New Issue
Block a user