B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
 * Recursively removes a directory or file fixing permissions when necessary.
 *
 * @param  aFile
 *         The nsIFile to remove
 */
Recursively removes a directory or file fixing permissions when necessary.
@param  aFile
The nsIFile to remove
Recursively removes a directory or file fixing permissions when necessary . @param aFile The nsIFile to remove
function recursiveRemove(aFile) {
  let isDir = null;
  try {
    isDir = aFile.isDirectory();
  }
  catch (e) {
    if (e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
      return;
    throw e;
  }
  setFilePermissions(aFile, isDir ? FileUtils.PERMS_DIRECTORY
                                  : FileUtils.PERMS_FILE);
  try {
    aFile.remove(true);
    return;
  }
  catch (e) {
    if (!aFile.isDirectory()) {
      ERROR("Failed to remove file " + aFile.path, e);
      throw e;
    }
  }
  let entries = getDirectoryEntries(aFile, true);
  entries.forEach(recursiveRemove);
  try {
    aFile.remove(true);
  }
  catch (e) {
    ERROR("Failed to remove empty directory " + aFile.path, e);
    throw e;
  }
}
function recursiveRemove ( aFile ) { let isDir = null ; try { isDir = aFile . isDirectory ( ) ; } catch ( e ) { if ( e . result == Cr . NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ) return ; throw e ; } setFilePermissions ( aFile , isDir ? FileUtils . PERMS_DIRECTORY : FileUtils . PERMS_FILE ) ; try { aFile . remove ( true ) ; return ; } catch ( e ) { if ( ! aFile . isDirectory ( ) ) { ERROR ( "Failed to remove file " + aFile . path , e ) ; throw e ; } } let entries = getDirectoryEntries ( aFile , true ) ; entries . forEach ( recursiveRemove ) ; try { aFile . remove ( true ) ; } catch ( e ) { ERROR ( "Failed to remove empty directory " + aFile . path , e ) ; throw e ; } }
Recursively removes a directory or file fixing permissions when necessary.
Recursively removes a directory or file fixing permissions when necessary .
// If the file has already gone away then don't worry about it, this can // happen on OSX where the resource fork is automatically moved with the // data fork for the file. See bug 733436. // Use a snapshot of the directory contents to avoid possible issues with // iterating over a directory while removing files from it (the YAFFS2 // embedded filesystem has this issue, see bug 772238), and to remove // normal files before their resource forks on OSX (see bug 733436).