Permalink
Browse files

fixed "must not be in the source directory"

  • Loading branch information...
1 parent 5cdcdd6 commit 1f09e6ee033e3cf21eedd540bd8d8c2f6f6ca62a @fengmk2 fengmk2 committed Dec 11, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 lib/jscover.js
View
@@ -34,9 +34,15 @@ module.exports = function jscover(source, target, options, callback) {
target = target || '';
options = options || [];
var tmpName = '__cov__' + Date.now();
- var tmpTargetDir = path.join(path.dirname(target), tmpName);
+ var tmpdir = process.env.TMPDIR || '/tmp';
+ var tmpTargetDir = path.join(tmpdir, tmpName);
var tmpTarget = path.join(tmpTargetDir, path.basename(target));
+ var cleanup = function () {
+ fse.removeSync(tmpTargetDir);
+ fse.removeSync(path.join(target, tmpName));
+ };
+
var cmd = JSCoverCommand;
if (options && options.length > 0) {
cmd += ' ' + options.join(' ');
@@ -59,6 +65,7 @@ module.exports = function jscover(source, target, options, callback) {
}
if (err) {
debug(err, stderr);
+ cleanup();
return callback(err, output);
}
@@ -88,10 +95,10 @@ module.exports = function jscover(source, target, options, callback) {
}
}
}, function end() {
- fse.removeSync(tmpTargetDir);
- fse.removeSync(path.join(target, tmpName));
+ cleanup();
callback();
}, function error(err, errPath) {
+ cleanup();
console.error('%s error: %s', errPath, err);
callback(err);
});

0 comments on commit 1f09e6e

Please sign in to comment.