bug 1299583 - Don't create backup of files when staging an update
authorRobert Strong <robert.bugzilla@gmail.com>
Wed, 31 Aug 2016 21:32:12 -0700
changeset 491566 8c2ab2591d7164856840baadd41616531f095c46
parent 491565 be3e1068535d1fe73e6da9231d31d9828701f5fa
child 491567 d497815cb5708e8e4297eb4f7aa961860cf49567
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
bugs1299583
milestone51.0a1
bug 1299583 - Don't create backup of files when staging an update
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -1203,35 +1203,47 @@ RemoveFile::Execute()
   // been removed by a separate instruction: bug 311099.
   int rv = NS_taccess(mFile.get(), F_OK);
   if (rv) {
     LOG(("file cannot be removed because it does not exist; skipping"));
     mSkip = 1;
     return OK;
   }
 
-  // Rename the old file. It will be removed in Finish.
-  rv = backup_create(mFile.get());
-  if (rv) {
-    LOG(("backup_create failed: %d", rv));
-    return rv;
+  if (sStagedUpdate) {
+    // Staged updates don't need backup files so just remove it.
+    rv = ensure_remove(mFile.get());
+    if (rv) {
+      return rv;
+    }
+  } else {
+    // Rename the old file. It will be removed in Finish.
+    rv = backup_create(mFile.get());
+    if (rv) {
+      LOG(("backup_create failed: %d", rv));
+      return rv;
+    }
   }
 
   return OK;
 }
 
 void
 RemoveFile::Finish(int status)
 {
-  if (mSkip)
+  if (mSkip) {
     return;
+  }
 
   LOG(("FINISH REMOVEFILE " LOG_S, mRelPath.get()));
 
-  backup_finish(mFile.get(), mRelPath.get(), status);
+  // Staged updates don't create backup files.
+  if (!sStagedUpdate) {
+    backup_finish(mFile.get(), mRelPath.get(), status);
+  }
 }
 
 class RemoveDir : public Action
 {
 public:
   RemoveDir() : mSkip(0) { }
 
   virtual int Parse(NS_tchar *line);
@@ -1396,19 +1408,25 @@ AddFile::Execute()
 {
   LOG(("EXECUTE ADD " LOG_S, mRelPath.get()));
 
   int rv;
 
   // First make sure that we can actually get rid of any existing file.
   rv = NS_taccess(mFile.get(), F_OK);
   if (rv == 0) {
-    rv = backup_create(mFile.get());
-    if (rv)
+    if (sStagedUpdate) {
+      // Staged updates don't need backup files so just remove it.
+      rv = ensure_remove(mFile.get());
+    } else {
+      rv = backup_create(mFile.get());
+    }
+    if (rv) {
       return rv;
+    }
   } else {
     rv = ensure_parent_dir(mFile.get());
     if (rv)
       return rv;
   }
 
 #ifdef XP_WIN
   char sourcefile[MAXPATHLEN];
@@ -1427,21 +1445,25 @@ AddFile::Execute()
   }
   return rv;
 }
 
 void
 AddFile::Finish(int status)
 {
   LOG(("FINISH ADD " LOG_S, mRelPath.get()));
-  // When there is an update failure and a file has been added it is removed
-  // here since there might not be a backup to replace it.
-  if (status && mAdded)
-    NS_tremove(mFile.get());
-  backup_finish(mFile.get(), mRelPath.get(), status);
+  // Staged updates don't create backup files.
+  if (!sStagedUpdate) {
+    // When there is an update failure and a file has been added it is removed
+    // here since there might not be a backup to replace it.
+    if (status && mAdded) {
+      NS_tremove(mFile.get());
+    }
+    backup_finish(mFile.get(), mRelPath.get(), status);
+  }
 }
 
 class PatchFile : public Action
 {
 public:
   PatchFile() : mPatchFile(nullptr), mPatchIndex(-1), buf(nullptr) { }
 
   virtual ~PatchFile();
@@ -1657,19 +1679,22 @@ PatchFile::Execute()
   struct NS_tstat_t ss;
   rv = NS_tstat(mFile.get(), &ss);
   if (rv) {
     LOG(("failed to read file status info: " LOG_S ", err: %d",
          mFileRelPath.get(), errno));
     return READ_ERROR;
   }
 
-  rv = backup_create(mFile.get());
-  if (rv) {
-    return rv;
+  // Staged updates don't need backup files.
+  if (!sStagedUpdate) {
+    rv = backup_create(mFile.get());
+    if (rv) {
+      return rv;
+    }
   }
 
 #if defined(HAVE_POSIX_FALLOCATE)
   AutoFile ofile(ensure_open(mFile.get(), NS_T("wb+"), ss.st_mode));
   posix_fallocate(fileno((FILE *)ofile), 0, header.dlen);
 #elif defined(XP_WIN)
   bool shouldTruncate = true;
   // Creating the file, setting the size, and then closing the file handle
@@ -1748,17 +1773,20 @@ PatchFile::Execute()
   return rv;
 }
 
 void
 PatchFile::Finish(int status)
 {
   LOG(("FINISH PATCH " LOG_S, mFileRelPath.get()));
 
-  backup_finish(mFile.get(), mFileRelPath.get(), status);
+  // Staged updates don't create backup files.
+  if (!sStagedUpdate) {
+    backup_finish(mFile.get(), mFileRelPath.get(), status);
+  }
 }
 
 class AddIfFile : public AddFile
 {
 public:
   virtual int Parse(NS_tchar *line);
   virtual int Prepare();
   virtual int Execute();