diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-12-19 15:23:10 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-12-19 15:23:10 +0300 |
commit | e5a2dee47c74f26c56fee5998545b97497e830c8 (patch) | |
tree | 7f29db5e5f6e563d5bffa2fd90d4ca6033570117 /node_modules/fs-vacuum | |
parent | 06ed569f2a6f588df4b110b024184afec18eb359 (diff) |
fs-vacuum@1.2.5
Mistakes were made. Windows-related mistakes. Now uses path-is-inside so
as to make fewer mistakes.
Diffstat (limited to 'node_modules/fs-vacuum')
-rw-r--r-- | node_modules/fs-vacuum/package.json | 11 | ||||
-rw-r--r-- | node_modules/fs-vacuum/vacuum.js | 17 |
2 files changed, 16 insertions, 12 deletions
diff --git a/node_modules/fs-vacuum/package.json b/node_modules/fs-vacuum/package.json index dc1516dbb..559b7bf2b 100644 --- a/node_modules/fs-vacuum/package.json +++ b/node_modules/fs-vacuum/package.json @@ -1,6 +1,6 @@ { "name": "fs-vacuum", - "version": "1.2.2", + "version": "1.2.5", "description": "recursively remove empty directories -- to a point", "main": "vacuum.js", "scripts": { @@ -31,12 +31,13 @@ }, "dependencies": { "graceful-fs": "^3.0.2", + "path-is-inside": "^1.0.1", "rimraf": "^2.2.8" }, "readme": "# fs-vacuum\n\nRemove the empty branches of a directory tree, optionally up to (but not\nincluding) a specified base directory. Optionally nukes the leaf directory.\n\n## Usage\n\n```javascript\nvar logger = require(\"npmlog\");\nvar vacuum = require(\"fs-vacuum\");\n\nvar options = {\n base : \"/path/to/my/tree/root\",\n purge : true,\n log : logger.silly.bind(logger, \"myCleanup\")\n};\n\n/* Assuming there are no other files or directories in \"out\", \"to\", or \"my\",\n * the final path will just be \"/path/to/my/tree/root\".\n */\nvacuum(\"/path/to/my/tree/root/out/to/my/files\", function (error) {\n if (error) console.error(\"Unable to cleanly vacuum:\", error.message);\n});\n```\n# vacuum(directory, options, callback)\n\n* `directory` {String} Leaf node to remove. **Must be a directory, symlink, or file.**\n* `options` {Object}\n * `base` {String} No directories at or above this level of the filesystem will be removed.\n * `purge` {Boolean} If set, nuke the whole leaf directory, including its contents.\n * `log` {Function} A logging function that takes `npmlog`-compatible argument lists.\n* `callback` {Function} Function to call once vacuuming is complete.\n * `error` {Error} What went wrong along the way, if anything.\n", "readmeFilename": "README.md", - "gitHead": "c788fcc30fe8e73725f4f202d86c51d23d9f3378", - "_id": "fs-vacuum@1.2.2", - "_shasum": "0e26ca2b14eb4ceb4b590a92aad585756ed18e40", - "_from": "fs-vacuum@>=1.2.2 <1.3.0" + "gitHead": "4911a38a65b6a6cb19fc980d18304e1cfca91fbf", + "_id": "fs-vacuum@1.2.5", + "_shasum": "a5cbaa844b4b3a7cff139f3cc90e7f7007e5fbb8", + "_from": "fs-vacuum@~1.2.5" } diff --git a/node_modules/fs-vacuum/vacuum.js b/node_modules/fs-vacuum/vacuum.js index 5880ae73d..e55abe970 100644 --- a/node_modules/fs-vacuum/vacuum.js +++ b/node_modules/fs-vacuum/vacuum.js @@ -1,6 +1,7 @@ -var assert = require("assert") -var dirname = require("path").dirname -var resolve = require("path").resolve +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 @@ -19,9 +20,10 @@ function vacuum(leaf, options, cb) { var log = options.log ? options.log : function () {} - var base = options.base - if (base && resolve(leaf).indexOf(resolve(base)) !== 0) { - return cb(new Error(resolve(leaf) + " is not a child of " + resolve(base))) + 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) { @@ -59,8 +61,9 @@ function vacuum(leaf, options, cb) { }) function next(branch) { + branch = branch && resolve(branch) // either we've reached the base or we've reached the root - if ((base && resolve(branch) === resolve(base)) || branch === dirname(branch)) { + if ((base && branch === base) || branch === dirname(branch)) { log("finished vacuuming up to", branch) return cb(null) } |