@@ -38,6 +38,7 @@ static char nameBuffer[PATH_MAX];
3838static struct stat statBuffer;
3939
4040static char copyBuffer[8192 ];
41+ static char *backupFilePath = NULL ;
4142
4243static uint32_t inputFileVersion;
4344
@@ -152,6 +153,10 @@ static int wipe (const char *path)
152153 strcat (nameBuffer, " /" );
153154
154155 } else {
156+ // Don't delete the backup file
157+ if (backupFilePath && strcmp (backupFilePath, nameBuffer) == 0 ) {
158+ continue ;
159+ }
155160 ret = unlink (nameBuffer);
156161
157162 if (ret != 0 ) {
@@ -279,7 +284,7 @@ static int backup_dir(FILE* fh, const char* srcPath)
279284 continue ;
280285 }
281286
282- if (fullPath = = NULL ) {
287+ if (fullPath ! = NULL ) {
283288 free (fullPath);
284289 }
285290 fullPath = (char *)malloc (srcLen + strlen (de->d_name ) + 2 );
@@ -320,8 +325,13 @@ static int backup_dir(FILE* fh, const char* srcPath)
320325 goto done;
321326 }
322327 } else if (S_ISREG (statBuffer.st_mode )) {
323- printf (" Saving file %s...\n " , fullPath);
324-
328+ // Skip the backup file
329+ if (backupFilePath && strcmp (fullPath, backupFilePath) == 0 ) {
330+ printf (" Skipping backup file %s...\n " , backupFilePath);
331+ continue ;
332+ } else {
333+ printf (" Saving file %s...\n " , fullPath);
334+ }
325335 if (write_header (fh, TYPE_FILE, fullPath, &statBuffer) == 0 ) {
326336 result = 0 ;
327337 goto done;
@@ -373,6 +383,9 @@ static int backup_data(const char* destPath)
373383
374384 printf (" Backing up /data to %s...\n " , destPath);
375385
386+ // The path that shouldn't be backed up
387+ backupFilePath = strdup (destPath);
388+
376389 if (!write_int32 (fh, FILE_VERSION)) goto done;
377390 if (!write_int32 (fh, opt_backupAll)) goto done;
378391 if (!backup_dir (fh, " /data" )) goto done;
@@ -509,6 +522,9 @@ static int restore_data(const char* srcPath)
509522 } else {
510523 opt_backupAll = 0 ;
511524 }
525+
526+ // The path that shouldn't be deleted
527+ backupFilePath = strdup (srcPath);
512528
513529 printf (" Wiping contents of /data...\n " );
514530 if (!wipe (" /data" )) {
0 commit comments