B2G/gecko/toolkit/mozapps/update/test/shared.js
/**
 * Removes all files and sub-directories in the updates directory except for
 * the "0" sub-directory.
 *
 * @param  aDir
 *         nsIFile for the directory to be deleted.
 */
Removes all files and sub-directories in the updates directory except for
the "0" sub-directory.

@param  aDir
nsIFile for the directory to be deleted.
Removes all files and sub - directories in the updates directory except for the " 0 " sub - directory . @param aDir nsIFile for the directory to be deleted .
function cleanUpdatesDir(aDir) {
  if (!aDir.exists())
    return;
  var dirEntries = aDir.directoryEntries;
  while (dirEntries.hasMoreElements()) {
    var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile);
    if (entry.isDirectory()) {
      if (entry.leafName == "0" && entry.parent.leafName == "updates") {
        cleanUpdatesDir(entry);
        entry.permissions = PERMS_DIRECTORY;
      }
      else {
        try {
          entry.remove(true);
          return;
        }
        catch (e) {
        }
        cleanUpdatesDir(entry);
        entry.permissions = PERMS_DIRECTORY;
        try {
          entry.remove(true);
        }
        catch (e) {
          dump("Unable to remove directory\npath: " + entry.path +
               "\nException: " + e + "\n");
          throw(e);
        }
      }
    }
    else {
      entry.permissions = PERMS_FILE;
      try {
        entry.remove(false);
      }
      catch (e) {
        dump("Unable to remove file\npath: " + entry.path + "\nException: " +
             e + "\n");
        throw(e);
      }
    }
  }
}
function cleanUpdatesDir ( aDir ) { if ( ! aDir . exists ( ) ) return ; var dirEntries = aDir . directoryEntries ; while ( dirEntries . hasMoreElements ( ) ) { var entry = dirEntries . getNext ( ) . QueryInterface ( AUS_Ci . nsIFile ) ; if ( entry . isDirectory ( ) ) { if ( entry . leafName == "0" && entry . parent . leafName == "updates" ) { cleanUpdatesDir ( entry ) ; entry . permissions = PERMS_DIRECTORY ; } else { try { entry . remove ( true ) ; return ; } catch ( e ) { } cleanUpdatesDir ( entry ) ; entry . permissions = PERMS_DIRECTORY ; try { entry . remove ( true ) ; } catch ( e ) { dump ( "Unable to remove directory\npath: " + entry . path + "\nException: " + e + "\n" ) ; throw ( e ) ; } } } else { entry . permissions = PERMS_FILE ; try { entry . remove ( false ) ; } catch ( e ) { dump ( "Unable to remove file\npath: " + entry . path + "\nException: " + e + "\n" ) ; throw ( e ) ; } } } }
Removes all files and sub-directories in the updates directory except for
 the "0" sub-directory.
Removes all files and sub - directories in the updates directory except for the " 0 " sub - directory .