B2G/gecko/services/sync/modules/policies.js
/**
   * Finds all logs older than maxErrorAge and deletes them without tying up I/O.
   */
Finds all logs older than maxErrorAge and deletes them without tying up I/O.
Finds all logs older than maxErrorAge and deletes them without tying up I / O .
function cleanupLogs() {
    let direntries = FileUtils.getDir("ProfD", ["weave", "logs"]).directoryEntries;
    let oldLogs = [];
    let index = 0;
    let threshold = Date.now() - 1000 * Svc.Prefs.get("log.appender.file.maxErrorAge");
    while (direntries.hasMoreElements()) {
      let logFile = direntries.getNext().QueryInterface(Ci.nsIFile);
      if (logFile.lastModifiedTime < threshold) {
        oldLogs.push(logFile);
      }
    }
    function deleteFile() {
      if (index >= oldLogs.length) {
        ErrorHandler._cleaningUpFileLogs = false;
        Svc.Obs.notify("weave:service:cleanup-logs");
        return;
      }
      try {
        oldLogs[index].remove(false);
      } catch (ex) {
        ErrorHandler._log._debug("Encountered error trying to clean up old log file '"
                                 + oldLogs[index].leafName + "':"
                                 + Utils.exceptionStr(ex));
      }
      index++;
      Utils.nextTick(deleteFile);
    }
    if (oldLogs.length > 0) {
      ErrorHandler._cleaningUpFileLogs = true;
      Utils.nextTick(deleteFile);
    }
  }
function cleanupLogs ( ) { let direntries = FileUtils . getDir ( "ProfD" , [ "weave" , "logs" ] ) . directoryEntries ; let oldLogs = [ ] ; let index = 0 ; let threshold = Date . now ( ) - 1000 * Svc . Prefs . get ( "log.appender.file.maxErrorAge" ) ; while ( direntries . hasMoreElements ( ) ) { let logFile = direntries . getNext ( ) . QueryInterface ( Ci . nsIFile ) ; if ( logFile . lastModifiedTime < threshold ) { oldLogs . push ( logFile ) ; } } function deleteFile ( ) { if ( index >= oldLogs . length ) { ErrorHandler . _cleaningUpFileLogs = false ; Svc . Obs . notify ( "weave:service:cleanup-logs" ) ; return ; } try { oldLogs [ index ] . remove ( false ) ; } catch ( ex ) { ErrorHandler . _log . _debug ( "Encountered error trying to clean up old log file '" + oldLogs [ index ] . leafName + "':" + Utils . exceptionStr ( ex ) ) ; } index ++ ; Utils . nextTick ( deleteFile ) ; } if ( oldLogs . length > 0 ) { ErrorHandler . _cleaningUpFileLogs = true ; Utils . nextTick ( deleteFile ) ; } }
Finds all logs older than maxErrorAge and deletes them without tying up I/O.
Finds all logs older than maxErrorAge and deletes them without tying up I / O .
// Deletes a file from oldLogs each tick until there are none left.