static struct stat statBuffer;
static char copyBuffer[8192];
+static char *backupFilePath = NULL;
static uint32_t inputFileVersion;
strcat(nameBuffer, "/");
} else {
+ // Don't delete the backup file
+ if (backupFilePath && strcmp(backupFilePath, nameBuffer) == 0) {
+ continue;
+ }
ret = unlink(nameBuffer);
if (ret != 0) {
continue;
}
- if (fullPath == NULL) {
+ if (fullPath != NULL) {
free(fullPath);
}
fullPath = (char*)malloc(srcLen + strlen(de->d_name) + 2);
goto done;
}
} else if (S_ISREG(statBuffer.st_mode)) {
- printf("Saving file %s...\n", fullPath);
-
+ // Skip the backup file
+ if (backupFilePath && strcmp(fullPath, backupFilePath) == 0) {
+ printf("Skipping backup file %s...\n", backupFilePath);
+ continue;
+ } else {
+ printf("Saving file %s...\n", fullPath);
+ }
if (write_header(fh, TYPE_FILE, fullPath, &statBuffer) == 0) {
result = 0;
goto done;
printf("Backing up /data to %s...\n", destPath);
+ // The path that shouldn't be backed up
+ backupFilePath = strdup(destPath);
+
if (!write_int32(fh, FILE_VERSION)) goto done;
if (!write_int32(fh, opt_backupAll)) goto done;
if (!backup_dir(fh, "/data")) goto done;
} else {
opt_backupAll = 0;
}
+
+ // The path that shouldn't be deleted
+ backupFilePath = strdup(srcPath);
printf("Wiping contents of /data...\n");
if (!wipe("/data")) {