[Pkg-javascript-commits] [node-tmp] 01/06: Imported Upstream version 0.0.28
Ross Gammon
ross-guest at moszumanska.debian.org
Sat Oct 17 14:41:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
ross-guest pushed a commit to branch master
in repository node-tmp.
commit 7f7b41b54392b478ef1b67ff36ff30315c2e2c77
Author: Ross Gammon <rossgammon at mail.dk>
Date: Sat Oct 17 16:15:08 2015 +0200
Imported Upstream version 0.0.28
---
.travis.yml | 2 ++
README.md | 2 +-
lib/tmp.js | 12 +++++++-----
package.json | 4 ++--
test/base.js | 13 +++++++++++--
test/dir-sync-test.js | 16 ++++++++++++++++
test/dir-test.js | 12 ++++++++++++
test/issue62-sync.js | 27 +++++++++++++++++++++++++++
test/issue62.js | 27 +++++++++++++++++++++++++++
test/unsafe-sync.js | 1 -
10 files changed, 105 insertions(+), 11 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 57ed561..ddf5948 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,3 +4,5 @@ node_js:
- "0.8"
- "0.10"
- "0.12"
+ - "4.0"
+ - "4.1"
diff --git a/README.md b/README.md
index ba29a2a..4e10016 100644
--- a/README.md
+++ b/README.md
@@ -124,7 +124,7 @@ tmp.tmpName(function _tempNameGenerated(err, path) {
### Synchronous filename generation
-A synchrounous version of the above.
+A synchronous version of the above.
```javascript
var tmp = require('tmp');
diff --git a/lib/tmp.js b/lib/tmp.js
index 50d696d..096c07e 100644
--- a/lib/tmp.js
+++ b/lib/tmp.js
@@ -262,7 +262,7 @@ function _rmdirRecursiveSync(root) {
do {
var
dir = dirs.pop(),
- canRemove = true,
+ deferred = false,
files = fs.readdirSync(dir);
for (var i = 0, length = files.length; i < length; i++) {
@@ -271,15 +271,17 @@ function _rmdirRecursiveSync(root) {
stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories
if (stat.isDirectory()) {
- canRemove = false;
- dirs.push(dir);
+ if (!deferred) {
+ deferred = true;
+ dirs.push(dir);
+ }
dirs.push(file);
} else {
fs.unlinkSync(file);
}
}
- if (canRemove) {
+ if (!deferred) {
fs.rmdirSync(dir);
}
} while (dirs.length !== 0);
@@ -370,8 +372,8 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
*
* @param {String} name
* @param {Object} opts
- * @api private
* @returns {Function} the callback
+ * @api private
*/
function _prepareTmpDirRemoveCallback(name, opts) {
var removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs.rmdirSync.bind(fs);
diff --git a/package.json b/package.json
index 5344814..7a82dce 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "tmp",
- "version": "0.0.27",
+ "version": "0.0.28",
"description": "Temporary file and directory creator",
"author": "KARASZI István <github at spam.raszi.hu> (http://raszi.hu/)",
@@ -29,7 +29,7 @@
},
"dependencies": {
- "os-tmpdir": "~1.0.0"
+ "os-tmpdir": "~1.0.1"
},
"devDependencies": {
diff --git a/test/base.js b/test/base.js
index 00094c7..a77f3a5 100644
--- a/test/base.js
+++ b/test/base.js
@@ -88,7 +88,7 @@ function _testGracefulSync(type, graceful, cb) {
function _assertName(err, name) {
assert.isString(name);
- assert.isNotZero(name.length);
+ assert.isNotZero(name.length, 'an empty string is not a valid name');
}
function _assertNameSync(result) {
@@ -118,10 +118,18 @@ function _testUnsafeCleanup(unsafe, cb) {
_spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
}
+function _testIssue62(cb) {
+ _spawnTestWithoutError('issue62.js', [], cb);
+}
+
function _testUnsafeCleanupSync(unsafe, cb) {
_spawnTestWithoutError('unsafe-sync.js', [ 'dir', unsafe ], cb);
}
+function _testIssue62Sync(cb) {
+ _spawnTestWithoutError('issue62-sync.js', [], cb);
+}
+
module.exports.testStat = _testStat;
module.exports.testPrefix = _testPrefix;
module.exports.testPrefixSync = _testPrefixSync;
@@ -136,5 +144,6 @@ module.exports.assertNameSync = _assertNameSync;
module.exports.testName = _testName;
module.exports.testNameSync = _testNameSync;
module.exports.testUnsafeCleanup = _testUnsafeCleanup;
+module.exports.testIssue62 = _testIssue62;
module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
-
+module.exports.testIssue62Sync = _testIssue62Sync;
diff --git a/test/dir-sync-test.js b/test/dir-sync-test.js
index 68d8d93..091a03e 100644
--- a/test/dir-sync-test.js
+++ b/test/dir-sync-test.js
@@ -188,6 +188,18 @@ vows.describe('Synchronous directory creation').addBatch({
}
},
+ 'unsafeCleanup === true with issue62 structure': {
+ topic: function () {
+ Test.testIssue62Sync(this.callback);
+ },
+
+ 'should not return with an error': assert.isNull,
+ 'should return with a name': Test.assertName,
+ 'should not exist': function (err, name) {
+ assert.ok(!existsSync(name), 'Directory should be removed');
+ }
+ },
+
'unsafeCleanup === false': {
topic: function () {
Test.testUnsafeCleanupSync('0', this.callback);
@@ -197,6 +209,10 @@ vows.describe('Synchronous directory creation').addBatch({
'should return with a name': Test.assertName,
'should be a directory': function (err, name) {
_testDir(040700)({name:name});
+ // make sure that everything gets cleaned up
+ fs.unlinkSync(path.join(name, 'should-be-removed.file'));
+ fs.unlinkSync(path.join(name, 'symlinkme-target'));
+ fs.rmdirSync(name);
}
},
diff --git a/test/dir-test.js b/test/dir-test.js
index 1a5739f..9f2c282 100644
--- a/test/dir-test.js
+++ b/test/dir-test.js
@@ -182,6 +182,18 @@ vows.describe('Directory creation').addBatch({
}
},
+ 'unsafeCleanup === true with issue62 structure': {
+ topic: function () {
+ Test.testIssue62(this.callback);
+ },
+
+ 'should not return with an error': assert.isNull,
+ 'should return with a name': Test.assertName,
+ 'should not exist': function (err, name) {
+ assert.ok(!existsSync(name), 'Directory should be removed');
+ }
+ },
+
'unsafeCleanup === false': {
topic: function () {
Test.testUnsafeCleanup('0', this.callback);
diff --git a/test/issue62-sync.js b/test/issue62-sync.js
new file mode 100644
index 0000000..94840c6
--- /dev/null
+++ b/test/issue62-sync.js
@@ -0,0 +1,27 @@
+
+var
+ fs = require('fs'),
+ join = require('path').join,
+ spawn = require('./spawn-sync');
+
+try {
+ var result = spawn.tmpFunction({ unsafeCleanup: true });
+ try {
+ // creates structure from issue 62
+ // https://github.com/raszi/node-tmp/issues/62
+
+ fs.mkdirSync(join(result.name, 'issue62'));
+
+ ['foo', 'bar'].forEach(function(subdir) {
+ fs.mkdirSync(join(result.name, 'issue62', subdir));
+ fs.writeFileSync(join(result.name, 'issue62', subdir, 'baz.txt'), '');
+ });
+
+ spawn.out(result.name, spawn.exit);
+ } catch (e) {
+ spawn.err(e.toString(), spawn.exit);
+ }
+}
+catch (e) {
+ spawn.err(e, spawn.exit);
+}
diff --git a/test/issue62.js b/test/issue62.js
new file mode 100644
index 0000000..004e190
--- /dev/null
+++ b/test/issue62.js
@@ -0,0 +1,27 @@
+var
+ fs = require('fs'),
+ join = require('path').join,
+ spawn = require('./spawn');
+
+spawn.tmpFunction({ unsafeCleanup: true }, function (err, name) {
+ if (err) {
+ spawn.err(err, spawn.exit);
+ return;
+ }
+
+ try {
+ // creates structure from issue 62
+ // https://github.com/raszi/node-tmp/issues/62
+
+ fs.mkdirSync(join(name, 'issue62'));
+
+ ['foo', 'bar'].forEach(function(subdir) {
+ fs.mkdirSync(join(name, 'issue62', subdir));
+ fs.writeFileSync(join(name, 'issue62', subdir, 'baz.txt'), '');
+ });
+
+ spawn.out(name, spawn.exit);
+ } catch (e) {
+ spawn.err(e.toString(), spawn.exit);
+ }
+});
diff --git a/test/unsafe-sync.js b/test/unsafe-sync.js
index f09129f..97717d0 100644
--- a/test/unsafe-sync.js
+++ b/test/unsafe-sync.js
@@ -28,4 +28,3 @@ try {
catch (e) {
spawn.err(err, spawn.exit);
}
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tmp.git
More information about the Pkg-javascript-commits
mailing list