bug 1299583 - Don't create backup of files when staging an update. r=mhowell
authorRobert Strong <robert.bugzilla@gmail.com>
Fri, 09 Sep 2016 11:53:57 -0700
changeset 313403 acb9b2a2bc968c9064b3d024a2d83f68faca27c5
parent 313402 0fda02f7c6a0000a95c5fe23debeb5653c6b96b7
child 313404 7078c20114e2afee1c05dc65cb853b6ab388afe9
push id81617
push userrstrong@mozilla.com
push dateFri, 09 Sep 2016 18:54:03 +0000
treeherdermozilla-inbound@acb9b2a2bc96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1299583
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1299583 - Don't create backup of files when staging an update. r=mhowell
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();