Error handler for `shutil.rmtree()` equivalent to `rm -rf`.

    Usage: `shutil.rmtree(path, onerror=force_delete)`
    From stackoverflow.com/questions/1889597
961772
def force_delete(func, path, exc_info):
    
    os.chmod(path, stat.S_IWRITE)
    func(path)
1308700
@Nonnull
  public static FileIOError deleteFile (@Nonnull final Path aFile)
  {
    ValueEnforcer.notNull (aFile, "Path");

    final Path aRealFile = _getUnifiedPath (aFile);

    if (!aRealFile.toFile ().isFile ())
      return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.DELETE_FILE, aRealFile);

    // Is the parent directory writable?
    final Path aParentDir = aRealFile.getParent ();
    if (aParentDir != null && !Files.isWritable (aParentDir))
      return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.DELETE_FILE, aRealFile);

    return _perform (EFileIOOperation.DELETE_FILE, Files::delete, aRealFile);
  }
730919
def remove(path):
    
    if not os.path.exists(path):
        return

    if os.path.isdir(path):
        return shutil.rmtree(path)

    if os.path.isfile(path):
        return os.remove(path)
1109922
def rm(path):
    
    if path and os.path.exists(path):
        if os.path.isdir(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
1118755
def rm(hdfs_path, recursive=True, user=None):
    
    host, port, path_ = path.split(hdfs_path, user)
    fs = hdfs(host, port, user)
    retval = fs.delete(path_, recursive=recursive)
    fs.close()
    return retval
373598
static function rmdir($dir, $deleteRoot = TRUE, $stopOnError = TRUE, &$debug = NULL)
	{
		if (is_dir($dir)) {
			if (NULL === $debug) $debug = [];
			try {
				foreach (glob($dir . '/*') as $file) {
					if (is_dir($file)) {
						self::rmdir($file, TRUE, $stopOnError, $debug);
					} else {
						$debug[] = printf("File: %s", Debug::path($file));
					}
					unlink($file);
				}
				if ($deleteRoot) {
					$debug[] = printf("Dir: %s", Debug::path($dir));
					rmdir($dir);
				}

				return TRUE;
			} catch (Exception $e) {
				if ($stopOnError) {
					$debug[] = $e->getMessage();
					return FALSE;
				}
			}
		}

		return FALSE;
	}
357966
def rmtree(path):
    """"""

    def onerror(func, path, exc_info):
        # Is the error an access error ?
        os.chmod(path, stat.S_IWUSR)

        try:
            func(path)  # Will scream if still not possible to delete.
        except Exception as ex:
            if HIDE_WINDOWS_KNOWN_ERRORS:
                raise SkipTest("FIXME: fails with: PermissionError\n  %s", ex)
            else:
                raise

    return shutil.rmtree(path, False, onerror)
916703
def delete_file_or_tree(*args):
    

    for f in args:
        try:
            os.unlink(f)
        except OSError:
            shutil.rmtree(f, ignore_errors=True)
648352
def rm(self, filename):
        """"""
        command = """
            try:
                import os
            except ImportError:
                import uos as os
            os.remove('{0}')
        """.format(
            filename
        )
        self._pyboard.enter_raw_repl()
        try:
            out = self._pyboard.exec_(textwrap.dedent(command))
        except PyboardError as ex:
            message = ex.args[2].decode("utf-8")
            # Check if this is an OSError #2, i.e. file/directory doesn't exist
            # and rethrow it as something more descriptive.
            if message.find("OSError: [Errno 2] ENOENT") != -1:
                raise RuntimeError("No such file/directory: {0}".format(filename))
            # Check for OSError #13, the directory isn't empty.
            if message.find("OSError: [Errno 13] EACCES") != -1:
                raise RuntimeError("Directory is not empty: {0}".format(filename))
            else:
                raise ex
        self._pyboard.exit_raw_repl()
704908
def __rmfile(path):
    
    logger.info("rmfile: %s" % path)
    try:
        os.remove(path)
        return True
    except Exception as e:
        logger.error("rmfile: %s failed! Error: %s" % (path, e))
        return False
795862
def uninstall(cls):
        """"""
        if os.path.exists(cls.home):
            shutil.rmtree(cls.home)
1149285
def register_rmtree(directory, cleaner=_mkdtemp_atexit_cleaner):
  """"""
  with _MKDTEMP_LOCK:
    _mkdtemp_register_cleaner(cleaner)
    _MKDTEMP_DIRS[os.getpid()].add(directory)
  return directory
315389
def remove(item):
    
    if os.path.isdir(item):
        shutil.rmtree(item)
    else:
        # Assume it's a file. error if not.
        os.remove(item)
824620
def rm_rf(z, path)
      z.get_children(:path => path).tap do |h|
        if h[:rc].zero?
          h[:children].each do |child|
            rm_rf(z, File.join(path, child))
          end
        elsif h[:rc] == ZNONODE
          # no-op
        else
          raise "Oh noes! unexpected return value! #{h.inspect}"
        end
      end

      rv = z.delete(:path => path)

      unless (rv[:rc].zero? or rv[:rc] == ZNONODE)
        raise "oh noes! failed to delete #{path}" 
      end

      path
    end
184277
def movetree(src, dst):
    
    try:
        shutil.move(src, dst)
    except:
        copytree(src, dst, symlinks=True, hardlinks=True)
        shutil.rmtree(src)
1287454
def close(self):
        

        if self.tmpdir:
            rmtree(self.tmpdir)
            self.tmpdir = None

        self._contents = None
1037364
def log_rmtree_error(func, arg, exc_info):
    """"""
    logging.warning("Failure during '%s(%s)': %s", func.__name__, arg, exc_info[1])