Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from c9/fix_mkfile_error_handling

fix error handling in mkfile
  • Loading branch information...
commit 1fff6845210495526651b90c877ebdb1c7500606 2 parents 9d8fb69 + 29f8c33
Lennart Kats lennartcl authored
Showing with 12 additions and 8 deletions.
  1. +11 −7 localfs.js
  2. +1 −1  package.json
18 localfs.js
View
@@ -337,7 +337,7 @@ module.exports = function setup(fsOptions) {
function mkfile(path, options, realCallback) {
var meta = {};
var called;
- var callback = function (err, meta) {
+ var callback = function (err) {
if (called) {
if (err) {
if (meta.stream) meta.stream.emit("error", err);
@@ -347,7 +347,7 @@ module.exports = function setup(fsOptions) {
return;
}
called = true;
- return realCallback.apply(this, arguments);
+ return realCallback(err, meta);
};
if (options.stream && !options.stream.readable) {
@@ -396,23 +396,27 @@ module.exports = function setup(fsOptions) {
});
function onPath(path) {
+ var hadError;
+
if (!options.mode) options.mode = umask & 0666;
var writable = new fs.WriteStream(path, options);
if (readable) {
readable.pipe(writable);
}
else {
- meta.stream = writable;
- callback(null, meta);
+ writable.on('open', function () {
+ if (hadError) return;
+ meta.stream = writable;
+ callback();
+ });
}
- var hadError;
- writable.once('error', function (err) {
+ writable.on('error', function (err) {
hadError = true;
error(err);
});
writable.on('close', function () {
if (hadError) return;
- callback(null, meta);
+ callback();
});
if (readable) {
2  package.json
View
@@ -6,7 +6,7 @@
],
"name": "vfs-local",
"description": "A vfs implementation that works on the local filesystem.",
- "version": "0.3.10",
+ "version": "0.3.11",
"repository": {
"type": "git",
"url": "git://github.com/c9/vfs-local.git"
Please sign in to comment.
Something went wrong with that request. Please try again.