Bug 1168728 draft
authorDaria <existential.defeat@gmail.com>
Tue, 28 Mar 2017 22:52:29 +0300
changeset 552615 eef93741e8f37e11f0fba8ec9d56b8d765aa7bca
parent 499907 dd2f2db1f87aa31e98d204a707dcfd6457a6c696
child 621870 376281eab26cb35d6660a564d1fde9be15035f4b
push id51414
push userbmo:existential.defeat@gmail.com
push dateTue, 28 Mar 2017 19:57:05 +0000
bugs1168728
milestone55.0a1
Bug 1168728 MozReview-Commit-ID: 9uMi92iTXPD
toolkit/components/telemetry/TelemetryStorage.jsm
--- a/toolkit/components/telemetry/TelemetryStorage.jsm
+++ b/toolkit/components/telemetry/TelemetryStorage.jsm
@@ -981,29 +981,35 @@ var TelemetryStorageImpl = {
       submitProbes(Math.round(archiveSizeInBytes / 1024 / 1024), 0, 0);
       return;
     }
 
     this._log.info("_enforceArchiveQuota - archive size: " + archiveSizeInBytes + "bytes"
                    + ", safety quota: " + SAFE_QUOTA + "bytes");
 
     startTimeStamp = Policy.now().getTime();
-    let pingsToPurge = pingList.slice(lastPingIndexToKeep + 1);
 
-    // Remove all the pings older than the last one which we are safe to keep.
-    for (let ping of pingsToPurge) {
-      if (this._shutdown) {
-        this._log.trace("_enforceArchiveQuota - Terminating the clean up task due to shutdown");
-        return;
-      }
-
+    // If the last one is newest and it's outdated, the rest are as well, so we remove the whole directory       
+     if (pingList.length-1==lastPingIndexToKeep){
+        this._log.trace("_removeArchivedPing - removing directory from: " + gPingsArchivePath);
+        this._archivedPings.clear();
+        OS.File.removeDir(gPingsArchivePath);
+    }else {
+         // Remove all the pings older than the last one which we are safe to keep.
+        let pingsToPurge = pingList.slice(lastPingIndexToKeep + 1);
+        for (let ping of pingsToPurge) {
+          if (this._shutdown) {
+          this._log.trace("_enforceArchiveQuota - Terminating the clean up task due to shutdown");
+           return;
+          }
       // This list is guaranteed to be in order, so remove the pings at its
       // beginning (oldest).
-      yield this._removeArchivedPing(ping.id, ping.timestampCreated, ping.type);
-    }
+         yield this._removeArchivedPing(ping.id, ping.timestampCreated, ping.type);
+        }
+      }
 
     const endTimeStamp = Policy.now().getTime();
     submitProbes(ARCHIVE_SIZE_PROBE_SPECIAL_VALUE, pingsToPurge.length,
                  Math.ceil(endTimeStamp - startTimeStamp));
   }),
 
   _cleanArchive: Task.async(function*() {
     this._log.trace("cleanArchiveTask");