-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Additional refactor & tons of tests for metadata update
- Loading branch information
Showing
13 changed files
with
1,368 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
'use strict'; | ||
|
||
var fs = require('graceful-fs'); | ||
var fo = require('../../fileOperations'); | ||
|
||
function writeBuffer(writePath, file, written) { | ||
var stat = file.stat; | ||
var opt = { | ||
mode: file.stat.mode, | ||
flag: file.flag, | ||
}; | ||
|
||
fs.open(writePath, file.flag, stat.mode, function(err, fd) { | ||
if (err) { | ||
return written(err); | ||
fo.writeFile(writePath, file.contents, opt, onWriteFile); | ||
|
||
function onWriteFile(writeErr, fd) { | ||
if (writeErr) { | ||
return fo.closeFd(writeErr, fd, written); | ||
} | ||
|
||
fs.write(fd, file.contents, 0, file.contents.length, 0, function(err) { | ||
written(err, fd, function(err1, finish) { | ||
fs.close(fd, function(err2) { | ||
finish(err1 || err2); | ||
}); | ||
}); | ||
}); | ||
}); | ||
fo.updateMetadata(fd, file, onUpdate); | ||
} | ||
|
||
function onUpdate(statErr, fd) { | ||
fo.closeFd(statErr, fd, written); | ||
} | ||
} | ||
|
||
module.exports = writeBuffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
'use strict'; | ||
|
||
var fs = require('graceful-fs'); | ||
var mkdirp = require('mkdirp'); | ||
|
||
var fo = require('../../fileOperations'); | ||
|
||
function writeDir(writePath, file, written) { | ||
mkdirp(writePath, file.stat.mode, written); | ||
mkdirp(writePath, file.stat.mode, onMkdirp); | ||
|
||
function onMkdirp(mkdirpErr) { | ||
if (mkdirpErr) { | ||
return written(mkdirpErr); | ||
} | ||
|
||
fs.open(writePath, 'r', onOpen); | ||
} | ||
|
||
function onOpen(openErr, fd) { | ||
// If we don't have access, just move along | ||
if (isInaccessible(openErr)) { | ||
return fo.closeFd(null, fd, written); | ||
} | ||
|
||
if (openErr) { | ||
return fo.closeFd(openErr, fd, written); | ||
} | ||
|
||
fo.updateMetadata(fd, file, onUpdate); | ||
} | ||
|
||
function onUpdate(statErr, fd) { | ||
fo.closeFd(statErr, fd, written); | ||
} | ||
} | ||
|
||
function isInaccessible(err) { | ||
if (!err) { | ||
return false; | ||
} | ||
|
||
if (err.code === 'EACCES') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
module.exports = writeDir; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.