Bug 1353956 - P5. Remove old v4 prefix files after new files are stored. r=gcp
☠☠ backed out by 4f6e4cbf401f ☠ ☠
authordlee <dlee@mozilla.com>
Tue, 05 Mar 2019 18:32:23 +0000
changeset 520663 f1f29fe519cf169d43eeacfe710d0b84e9da55db
parent 520662 4978556a66f66cd6d214f98aa656ea1e223ead63
child 520664 71dafccc22ae493b656d9130cec82ba37d4babf7
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1353956
milestone67.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 1353956 - P5. Remove old v4 prefix files after new files are stored. r=gcp This patch is to cleanup old SafeBrowsing v4 prefix files. Differential Revision: https://phabricator.services.mozilla.com/D21464
toolkit/components/url-classifier/LookupCacheV4.cpp
toolkit/components/url-classifier/LookupCacheV4.h
--- a/toolkit/components/url-classifier/LookupCacheV4.cpp
+++ b/toolkit/components/url-classifier/LookupCacheV4.cpp
@@ -303,16 +303,49 @@ nsresult LookupCacheV4::StoreToFile(nsCO
   }
 
   rv = safeOut->Finish();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   LOG(("[%s] Storing PrefixSet successful", mTableName.get()));
+
+  // This is to remove old ".pset" files if exist
+  Unused << CleanOldPrefixSet();
+  return NS_OK;
+}
+
+nsresult LookupCacheV4::CleanOldPrefixSet() {
+  nsCOMPtr<nsIFile> file;
+  nsresult rv = mStoreDirectory->Clone(getter_AddRefs(file));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  rv = file->AppendNative(mTableName + NS_LITERAL_CSTRING(".pset"));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  bool exists;
+  rv = file->Exists(&exists);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  if (exists) {
+    rv = file->Remove(false);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    LOG(("[%s] Old PrefixSet is succuessfully removed!", mTableName.get()));
+  }
+
   return NS_OK;
 }
 
 nsresult LookupCacheV4::LoadFromFile(nsCOMPtr<nsIFile>& aFile) {
   NS_ENSURE_ARG_POINTER(aFile);
 
   Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_VLPS_FILELOAD_TIME> timer;
 
--- a/toolkit/components/url-classifier/LookupCacheV4.h
+++ b/toolkit/components/url-classifier/LookupCacheV4.h
@@ -61,16 +61,17 @@ class LookupCacheV4 final : public Looku
 
   struct Header {
     uint32_t magic;
     uint32_t version;
   };
 
   nsresult SanityCheck(const Header& aHeader);
   nsresult VerifyCRC32(nsCOMPtr<nsIInputStream>& aIn);
+  nsresult CleanOldPrefixSet();
 
   RefPtr<VariableLengthPrefixSet> mVLPrefixSet;
 };
 
 }  // namespace safebrowsing
 }  // namespace mozilla
 
 #endif