Bug 1423917 - P1 - Ignore dot files in QM and add .desktop, Desktop.ini, desktop.ini, Thumbs.db into the list of OSMetadata; r=asuth a=lizzard
authorTom Tung <shes050117@gmail.com>
Thu, 20 Sep 2018 14:54:42 +0200
changeset 515942 4b73d443d7716a561aaca29838cf41385add16ef
parent 515941 6ce3886d5cc5a6cf65a153fb76ed3c42c9145b93
child 515943 d6e47c340828f443a824ec136d52d6d21d6e1d99
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, lizzard
bugs1423917, 944918, 1493262
milestone66.0
Bug 1423917 - P1 - Ignore dot files in QM and add .desktop, Desktop.ini, desktop.ini, Thumbs.db into the list of OSMetadata; r=asuth a=lizzard This patch mainly whitelist all the dot-files in the persistence directories and origin directories. Ignore dot-files was first proposed in Bug 944918 comment 39. ".desktop" was also mentioned in that comment Besides, "desktop.ini" was first mentioned in Bug 944918 comment 42, "Thumbs.db" was mentioned in 1493262 comment 11, and "Desktop.ini" was first mentioned Bug 1423917 comment 46.Thus, this patch also whitelist them all during initialization.
dom/indexedDB/ActorsParent.cpp
dom/quota/ActorsParent.cpp
dom/quota/QuotaCommon.h
dom/quota/QuotaManager.h
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -15881,20 +15881,25 @@ nsresult QuotaClient::GetDatabaseFilenam
       return rv;
     }
 
     if (isDirectory) {
       aSubdirsToProcess.AppendElement(leafName);
       continue;
     }
 
-    // Skip Desktop Service Store (.DS_Store) files. These files are only used
-    // on Mac OS X, but the profile can be shared across different operating
-    // systems, so we check it on all platforms.
-    if (leafName.EqualsLiteral(DSSTORE_FILE_NAME)) {
+    // Skip OS metadata files. These files are only used in different platforms,
+    // but the profile can be shared across different operating systems, so we
+    // check it on all platforms.
+    if (QuotaManager::IsOSMetadata(leafName)) {
+      continue;
+    }
+
+    // Skip files starting with ".".
+    if (QuotaManager::IsDotFile(leafName)) {
       continue;
     }
 
     // Skip SQLite temporary files. These files take up space on disk but will
     // be deleted as soon as the database is opened, so we don't count them
     // towards quota.
     if (StringEndsWith(leafName, journalSuffix) ||
         StringEndsWith(leafName, shmSuffix)) {
@@ -15960,16 +15965,21 @@ nsresult QuotaClient::GetUsageForDirecto
   while (NS_SUCCEEDED((rv = entries->GetNextFile(getter_AddRefs(file)))) &&
          file && !aCanceled) {
     nsString leafName;
     rv = file->GetLeafName(leafName);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
+    if (QuotaManager::IsOSMetadata(leafName) ||
+        QuotaManager::IsDotFile(leafName)) {
+      continue;
+    }
+
     // Journal files and sqlite-shm files don't count towards usage.
     if (StringEndsWith(leafName, journalSuffix) ||
         StringEndsWith(leafName, shmSuffix)) {
       continue;
     }
 
     bool isDirectory;
     rv = file->IsDirectory(&isDirectory);
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -1262,18 +1262,22 @@ void AssertNoOverflow(uint64_t aDest, T 
 
 template <typename T, typename U>
 void AssertNoUnderflow(T aDest, U aArg) {
   IntChecker<T>::Assert(aDest);
   IntChecker<T>::Assert(aArg);
   MOZ_ASSERT(uint64_t(aDest) >= uint64_t(aArg));
 }
 
-bool IsOSMetadata(const nsAString& aFileName) {
-  return aFileName.EqualsLiteral(DSSTORE_FILE_NAME);
+inline bool IsDotFile(const nsAString& aFileName) {
+  return QuotaManager::IsDotFile(aFileName);
+}
+
+inline bool IsOSMetadata(const nsAString& aFileName) {
+  return QuotaManager::IsOSMetadata(aFileName);
 }
 
 bool IsOriginMetadata(const nsAString& aFileName) {
   return aFileName.EqualsLiteral(METADATA_FILE_NAME) ||
          aFileName.EqualsLiteral(METADATA_V2_FILE_NAME) ||
          IsOSMetadata(aFileName);
 }
 
@@ -1663,17 +1667,18 @@ int64_t GetLastModifiedTime(nsIFile* aFi
 
       if (!isDirectory) {
         nsString leafName;
         rv = aFile->GetLeafName(leafName);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
 
-        if (IsOriginMetadata(leafName) || IsTempMetadata(leafName)) {
+        if (IsOriginMetadata(leafName) || IsTempMetadata(leafName) ||
+            IsDotFile(leafName)) {
           return NS_OK;
         }
 
         int64_t timestamp;
         rv = aFile->GetLastModifiedTime(&timestamp);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
@@ -2864,16 +2869,29 @@ void QuotaManager::GetOrCreate(nsIRunnab
 QuotaManager* QuotaManager::Get() {
   // Does not return an owning reference.
   return gInstance;
 }
 
 // static
 bool QuotaManager::IsShuttingDown() { return gShutdown; }
 
+// static
+bool QuotaManager::IsOSMetadata(const nsAString& aFileName) {
+  return aFileName.EqualsLiteral(DSSTORE_FILE_NAME) ||
+         aFileName.EqualsLiteral(DESKTOP_FILE_NAME) ||
+         aFileName.LowerCaseEqualsLiteral(DESKTOP_INI_FILE_NAME) ||
+         aFileName.EqualsLiteral(THUMBS_DB_FILE_NAME);
+}
+
+// static
+bool QuotaManager::IsDotFile(const nsAString& aFileName) {
+  return aFileName.First() == char16_t('.');
+}
+
 auto QuotaManager::CreateDirectoryLock(
     const Nullable<PersistenceType>& aPersistenceType, const nsACString& aGroup,
     const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
     bool aExclusive, bool aInternal, OpenDirectoryListener* aOpenListener)
     -> already_AddRefed<DirectoryLockImpl> {
   AssertIsOnOwningThread();
   MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
   MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull());
@@ -3758,17 +3776,17 @@ nsresult QuotaManager::InitializeReposit
       nsString leafName;
       rv = childDirectory->GetLeafName(leafName);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         REPORT_TELEMETRY_INIT_ERR(kExternalError, Rep_GetLeafName);
         RECORD_IN_NIGHTLY(statusKeeper, rv);
         CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(rv);
       }
 
-      if (IsOSMetadata(leafName)) {
+      if (IsOSMetadata(leafName) || IsDotFile(leafName)) {
         continue;
       }
 
       UNKNOWN_FILE_WARNING(leafName);
 
       REPORT_TELEMETRY_INIT_ERR(kInternalError, Rep_UnexpectedFile);
       RECORD_IN_NIGHTLY(statusKeeper, NS_ERROR_UNEXPECTED);
       CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(NS_ERROR_UNEXPECTED);
@@ -3875,16 +3893,20 @@ nsresult QuotaManager::InitializeOrigin(
           REPORT_TELEMETRY_INIT_ERR(kExternalError, Ori_Remove);
           RECORD_IN_NIGHTLY(statusKeeper, rv);
           CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(rv);
         }
 
         continue;
       }
 
+      if (IsOSMetadata(leafName) || IsDotFile(leafName)) {
+        continue;
+      }
+
       UNKNOWN_FILE_WARNING(leafName);
       REPORT_TELEMETRY_INIT_ERR(kInternalError, Ori_UnexpectedFile);
       RECORD_IN_NIGHTLY(statusKeeper, NS_ERROR_UNEXPECTED);
       CONTINUE_IN_NIGHTLY_RETURN_IN_OTHERS(NS_ERROR_UNEXPECTED);
     }
 
     Client::Type clientType;
     rv = Client::TypeFromText(leafName, clientType);
@@ -6611,16 +6633,20 @@ nsresult QuotaUsageRequestBase::GetUsage
             if (NS_WARN_IF(NS_FAILED(rv))) {
               return rv;
             }
           }
 
           continue;
         }
 
+        if (IsOSMetadata(leafName) || IsDotFile(leafName)) {
+          continue;
+        }
+
         UNKNOWN_FILE_WARNING(leafName);
         if (!initialized) {
           return NS_ERROR_UNEXPECTED;
         }
         continue;
       }
 
       Client::Type clientType;
@@ -6738,16 +6764,18 @@ nsresult GetUsageOp::TraverseRepository(
 
     if (!isDirectory) {
       nsString leafName;
       rv = originDir->GetLeafName(leafName);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
+      // Unknown files during getting usages are allowed. Just warn if we find
+      // them.
       if (!IsOSMetadata(leafName)) {
         UNKNOWN_FILE_WARNING(leafName);
       }
       continue;
     }
 
     int64_t timestamp;
     bool persisted;
--- a/dom/quota/QuotaCommon.h
+++ b/dom/quota/QuotaCommon.h
@@ -19,16 +19,19 @@
   namespace quota {
 #define END_QUOTA_NAMESPACE \
   } /* namespace quota */   \
   } /* namespace dom */     \
   } /* namespace mozilla */
 #define USING_QUOTA_NAMESPACE using namespace mozilla::dom::quota;
 
 #define DSSTORE_FILE_NAME ".DS_Store"
+#define DESKTOP_FILE_NAME ".desktop"
+#define DESKTOP_INI_FILE_NAME "desktop.ini"
+#define THUMBS_DB_FILE_NAME "Thumbs.db"
 
 #define QM_WARNING(...)                                                      \
   do {                                                                       \
     nsPrintfCString str(__VA_ARGS__);                                        \
     mozilla::dom::quota::ReportInternalError(__FILE__, __LINE__, str.get()); \
     NS_WARNING(str.get());                                                   \
   } while (0)
 
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -110,16 +110,20 @@ class QuotaManager final : public Backgr
                           nsIEventTarget* aMainEventTarget = nullptr);
 
   // Returns a non-owning reference.
   static QuotaManager* Get();
 
   // Returns true if we've begun the shutdown process.
   static bool IsShuttingDown();
 
+  static bool IsOSMetadata(const nsAString& aFileName);
+
+  static bool IsDotFile(const nsAString& aFileName);
+
   bool IsOriginInitialized(const nsACString& aOrigin) const {
     AssertIsOnIOThread();
 
     return mInitializedOrigins.Contains(aOrigin);
   }
 
   bool IsTemporaryStorageInitialized() const {
     AssertIsOnIOThread();