pax_global_header00006660000000000000000000000064121732557020014516gustar00rootroot0000000000000052 comment=1ae2fb70ea0a39b0122a1c2476df22a3a97b5819 rimraf-2.2.2/000077500000000000000000000000001217325570200130015ustar00rootroot00000000000000rimraf-2.2.2/AUTHORS000066400000000000000000000003531217325570200140520ustar00rootroot00000000000000# Authors sorted by whether or not they're me. Isaac Z. Schlueter (http://blog.izs.me) Wayne Larsen (http://github.com/wvl) ritch Marcel Laverdet Yosef Dinerstein rimraf-2.2.2/LICENSE000066400000000000000000000021041217325570200140030ustar00rootroot00000000000000Copyright 2009, 2010, 2011 Isaac Z. Schlueter. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rimraf-2.2.2/README.md000066400000000000000000000012561217325570200142640ustar00rootroot00000000000000A `rm -rf` for node. Install with `npm install rimraf`, or just drop rimraf.js somewhere. ## API `rimraf(f, callback)` The callback will be called with an error if there is one. Certain errors are handled for you: * `EBUSY` - rimraf will back off a maximum of opts.maxBusyTries times before giving up. * `EMFILE` - If too many file descriptors get opened, rimraf will patiently wait until more become available. ## rimraf.sync It can remove stuff synchronously, too. But that's not so good. Use the async API. It's better. ## CLI If installed with `npm install rimraf -g` it can be used as a global command `rimraf ` which is useful for cross platform support. rimraf-2.2.2/bin.js000077500000000000000000000013501217325570200141110ustar00rootroot00000000000000#!/usr/bin/env node var rimraf = require('./') var help = false var dashdash = false var args = process.argv.slice(2).filter(function(arg) { if (dashdash) return !!arg else if (arg === '--') dashdash = true else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/)) help = true else return !!arg }); if (help || args.length === 0) { // If they didn't ask for help, then this is not a "success" var log = help ? console.log : console.error log('Usage: rimraf ') log('') log(' Deletes all files and folders at "path" recursively.') log('') log('Options:') log('') log(' -h, --help Display this usage info') process.exit(help ? 0 : 1) } else { args.forEach(function(arg) { rimraf.sync(arg) }) } rimraf-2.2.2/package.json000066400000000000000000000007601217325570200152720ustar00rootroot00000000000000{ "name": "rimraf", "version": "2.2.2", "main": "rimraf.js", "description": "A deep deletion module for node (like `rm -rf`)", "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "license": { "type": "MIT", "url": "https://github.com/isaacs/rimraf/raw/master/LICENSE" }, "optionalDependencies": { "graceful-fs": "~2" }, "repository": "git://github.com/isaacs/rimraf.git", "scripts": { "test": "cd test && bash run.sh" }, "bin": "./bin.js" } rimraf-2.2.2/rimraf.js000066400000000000000000000103031217325570200146140ustar00rootroot00000000000000module.exports = rimraf rimraf.sync = rimrafSync var path = require("path") , fs try { // optional dependency fs = require("graceful-fs") } catch (er) { fs = require("fs") } // for EMFILE handling var timeout = 0 exports.EMFILE_MAX = 1000 exports.BUSYTRIES_MAX = 3 var isWindows = (process.platform === "win32") function rimraf (p, cb) { if (!cb) throw new Error("No callback passed to rimraf()") var busyTries = 0 rimraf_(p, function CB (er) { if (er) { if (er.code === "EBUSY" && busyTries < exports.BUSYTRIES_MAX) { busyTries ++ var time = busyTries * 100 // try again, with the same exact callback as this one. return setTimeout(function () { rimraf_(p, CB) }, time) } // this one won't happen if graceful-fs is used. if (er.code === "EMFILE" && timeout < exports.EMFILE_MAX) { return setTimeout(function () { rimraf_(p, CB) }, timeout ++) } // already gone if (er.code === "ENOENT") er = null } timeout = 0 cb(er) }) } // Two possible strategies. // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR // // Both result in an extra syscall when you guess wrong. However, there // are likely far more normal files in the world than directories. This // is based on the assumption that a the average number of files per // directory is >= 1. // // If anyone ever complains about this, then I guess the strategy could // be made configurable somehow. But until then, YAGNI. function rimraf_ (p, cb) { fs.unlink(p, function (er) { if (er) { if (er.code === "ENOENT") return cb() if (er.code === "EPERM") return (isWindows) ? fixWinEPERM(p, er, cb) : rmdir(p, er, cb) if (er.code === "EISDIR") return rmdir(p, er, cb) } return cb(er) }) } function fixWinEPERM (p, er, cb) { fs.chmod(p, 666, function (er2) { if (er2) cb(er2.code === "ENOENT" ? null : er) else fs.stat(p, function(er3, stats) { if (er3) cb(er3.code === "ENOENT" ? null : er) else if (stats.isDirectory()) rmdir(p, er, cb) else fs.unlink(p, cb) }) }) } function fixWinEPERMSync (p, er, cb) { try { fs.chmodSync(p, 666) } catch (er2) { if (er2.code !== "ENOENT") throw er } try { var stats = fs.statSync(p) } catch (er3) { if (er3 !== "ENOENT") throw er } if (stats.isDirectory()) rmdirSync(p, er) else fs.unlinkSync(p) } function rmdir (p, originalEr, cb) { // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS) // if we guessed wrong, and it's not a directory, then // raise the original error. fs.rmdir(p, function (er) { if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST")) rmkids(p, cb) else if (er && er.code === "ENOTDIR") cb(originalEr) else cb(er) }) } function rmkids(p, cb) { fs.readdir(p, function (er, files) { if (er) return cb(er) var n = files.length if (n === 0) return fs.rmdir(p, cb) var errState files.forEach(function (f) { rimraf(path.join(p, f), function (er) { if (errState) return if (er) return cb(errState = er) if (--n === 0) fs.rmdir(p, cb) }) }) }) } // this looks simpler, and is strictly *faster*, but will // tie up the JavaScript thread and fail on excessively // deep directory trees. function rimrafSync (p) { try { fs.unlinkSync(p) } catch (er) { if (er.code === "ENOENT") return if (er.code === "EPERM") return isWindows ? fixWinEPERMSync(p, er) : rmdirSync(p, er) if (er.code !== "EISDIR") throw er rmdirSync(p, er) } } function rmdirSync (p, originalEr) { try { fs.rmdirSync(p) } catch (er) { if (er.code === "ENOENT") return if (er.code === "ENOTDIR") throw originalEr if (er.code === "ENOTEMPTY" || er.code === "EEXIST") rmkidsSync(p) } } function rmkidsSync (p) { fs.readdirSync(p).forEach(function (f) { rimrafSync(path.join(p, f)) }) fs.rmdirSync(p) } rimraf-2.2.2/test/000077500000000000000000000000001217325570200137605ustar00rootroot00000000000000rimraf-2.2.2/test/run.sh000066400000000000000000000002101217325570200151110ustar00rootroot00000000000000#!/bin/bash set -e for i in test-*.js; do echo -n $i ... bash setup.sh node $i ! [ -d target ] echo "pass" done rm -rf target rimraf-2.2.2/test/setup.sh000066400000000000000000000011321217325570200154510ustar00rootroot00000000000000#!/bin/bash set -e files=10 folders=2 depth=4 target="$PWD/target" rm -rf target fill () { local depth=$1 local files=$2 local folders=$3 local target=$4 if ! [ -d $target ]; then mkdir -p $target fi local f f=$files while [ $f -gt 0 ]; do touch "$target/f-$depth-$f" let f-- done let depth-- if [ $depth -le 0 ]; then return 0 fi f=$folders while [ $f -gt 0 ]; do mkdir "$target/folder-$depth-$f" fill $depth $files $folders "$target/d-$depth-$f" let f-- done } fill $depth $files $folders $target # sanity assert [ -d $target ] rimraf-2.2.2/test/test-async.js000066400000000000000000000002121217325570200164030ustar00rootroot00000000000000var rimraf = require("../rimraf") , path = require("path") rimraf(path.join(__dirname, "target"), function (er) { if (er) throw er }) rimraf-2.2.2/test/test-sync.js000066400000000000000000000001511217325570200162440ustar00rootroot00000000000000var rimraf = require("../rimraf") , path = require("path") rimraf.sync(path.join(__dirname, "target"))