Server IP : 127.0.0.2 / Your IP : 3.145.15.153 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/fs-vacuum/ |
Upload File : |
var assert = require("assert") var dirname = require("path").dirname var resolve = require("path").resolve var isInside = require("path-is-inside") var rimraf = require("rimraf") var lstat = require("graceful-fs").lstat var readdir = require("graceful-fs").readdir var rmdir = require("graceful-fs").rmdir var unlink = require("graceful-fs").unlink module.exports = vacuum function vacuum(leaf, options, cb) { assert(typeof leaf === "string", "must pass in path to remove") assert(typeof cb === "function", "must pass in callback") if (!options) options = {} assert(typeof options === "object", "options must be an object") var log = options.log ? options.log : function () {} leaf = leaf && resolve(leaf) var base = options.base && resolve(options.base) if (base && !isInside(leaf, base)) { return cb(new Error(leaf + " is not a child of " + base)) } lstat(leaf, function (error, stat) { if (error) { if (error.code === "ENOENT") return cb(null) log(error.stack) return cb(error) } if (!(stat && (stat.isDirectory() || stat.isSymbolicLink() || stat.isFile()))) { log(leaf, "is not a directory, file, or link") return cb(new Error(leaf + " is not a directory, file, or link")) } if (options.purge) { log("purging", leaf) rimraf(leaf, function (error) { if (error) return cb(error) next(dirname(leaf)) }) } else if (!stat.isDirectory()) { log("removing", leaf) unlink(leaf, function (error) { if (error) return cb(error) next(dirname(leaf)) }) } else { next(leaf) } }) function next(branch) { branch = branch && resolve(branch) // either we've reached the base or we've reached the root if ((base && branch === base) || branch === dirname(branch)) { log("finished vacuuming up to", branch) return cb(null) } readdir(branch, function (error, files) { if (error) { if (error.code === "ENOENT") return cb(null) log("unable to check directory", branch, "due to", error.message) return cb(error) } if (files.length > 0) { log("quitting because other entries in", branch) return cb(null) } log("removing", branch) lstat(branch, function (error, stat) { if (error) { if (error.code === "ENOENT") return cb(null) log("unable to lstat", branch, "due to", error.message) return cb(error) } var remove = stat.isDirectory() ? rmdir : unlink remove(branch, function (error) { if (error) { if (error.code === "ENOENT") { log("quitting because lost the race to remove", branch) return cb(null) } if (error.code === "ENOTEMPTY") { log("quitting because new (racy) entries in", branch) return cb(null) } log("unable to remove", branch, "due to", error.message) return cb(error) } next(dirname(branch)) }) }) }) } }