Bug 1279145 - log manager now cleans old Sync and ReadingList log files. r?tcsc draft
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 18 Jul 2016 11:46:01 +1000
changeset 388812 c99de01188a6c36758746529915dc84e5414d21a
parent 387451 31cab0ba8bbf1d88b08abeae45bcdf317645355a
child 525603 9c9773b1053f27f9a5cb398b8246d125e9b885e7
push id23238
push userbmo:markh@mozilla.com
push dateMon, 18 Jul 2016 01:46:24 +0000
reviewerstcsc
bugs1279145
milestone50.0a1
Bug 1279145 - log manager now cleans old Sync and ReadingList log files. r?tcsc MozReview-Commit-ID: JpispWkvlFZ
services/common/logmanager.js
--- a/services/common/logmanager.js
+++ b/services/common/logmanager.js
@@ -127,24 +127,23 @@ FlushableStorageAppender.prototype = {
       }
     }
     log.trace("finished copy to", fullOutputFileName);
   }),
 }
 
 // The public LogManager object.
 function LogManager(prefRoot, logNames, logFilePrefix) {
+  this._prefObservers = [];
   this.init(prefRoot, logNames, logFilePrefix);
 }
 
 LogManager.prototype = {
   _cleaningUpFileLogs: false,
 
-  _prefObservers: [],
-
   init(prefRoot, logNames, logFilePrefix) {
     if (prefRoot instanceof Preferences) {
       this._prefs = prefRoot;
     } else {
       this._prefs = new Preferences(prefRoot);
     }
 
     this.logFilePrefix = logFilePrefix;
@@ -296,18 +295,21 @@ LogManager.prototype = {
     this._cleaningUpFileLogs = true;
     let logDir = FileUtils.getDir("ProfD", this._logFileSubDirectoryEntries);
     let iterator = new OS.File.DirectoryIterator(logDir.path);
     let maxAge = this._prefs.get("log.appender.file.maxErrorAge", DEFAULT_MAX_ERROR_AGE);
     let threshold = Date.now() - 1000 * maxAge;
 
     this._log.debug("Log cleanup threshold time: " + threshold);
     yield iterator.forEach(Task.async(function* (entry) {
-      if (!entry.name.startsWith("error-" + this.logFilePrefix + "-") &&
-          !entry.name.startsWith("success-" + this.logFilePrefix + "-")) {
+      // Note that we don't check this.logFilePrefix is in the name - we cleanup
+      // all files in this directory regardless of that prefix so old logfiles
+      // for prefixes no longer in use are still cleaned up. See bug 1279145.
+      if (!entry.name.startsWith("error-") &&
+          !entry.name.startsWith("success-")) {
         return;
       }
       try {
         // need to call .stat() as the enumerator doesn't give that to us on *nix.
         let info = yield OS.File.stat(entry.path);
         if (info.lastModificationDate.getTime() >= threshold) {
           return;
         }