-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promisify fs
methods
#62
Changes from 1 commit
c334191
ba4e0a5
b9ea3f9
35fe3dc
acb91b9
d987f8f
9e80a4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,23 +23,21 @@ function fsOperationFailed(stream, sourceFile, err) { | |
const sha1 = buf => crypto.createHash('sha1').update(buf).digest('hex'); | ||
|
||
// Only push through files changed more recently than the destination files | ||
function compareLastModifiedTime(stream, cb, sourceFile, targetPath) { | ||
stat(targetPath) | ||
function compareLastModifiedTime(stream, sourceFile, targetPath) { | ||
return stat(targetPath) | ||
.then(targetStat => { | ||
if (sourceFile.stat && sourceFile.stat.mtime > targetStat.mtime) { | ||
stream.push(sourceFile); | ||
} | ||
}) | ||
.catch(err => fsOperationFailed(stream, sourceFile, err)) | ||
.then(() => cb()); | ||
.catch(err => fsOperationFailed(stream, sourceFile, err)); | ||
} | ||
|
||
// Only push through files with different SHA1 than the destination files | ||
function compareSha1Digest(stream, cb, sourceFile, targetPath) { | ||
readFile(targetPath) | ||
function compareSha1Digest(stream, sourceFile, targetPath) { | ||
return readFile(targetPath) | ||
.then(targetData => { | ||
if (sourceFile.isNull()) { | ||
cb(null, sourceFile); | ||
return; | ||
} | ||
|
||
|
@@ -50,8 +48,7 @@ function compareSha1Digest(stream, cb, sourceFile, targetPath) { | |
stream.push(sourceFile); | ||
} | ||
}) | ||
.catch(err => fsOperationFailed(stream, sourceFile, err)) | ||
.then(() => cb()); | ||
.catch(err => fsOperationFailed(stream, sourceFile, err)); | ||
} | ||
|
||
module.exports = (dest, opts) => { | ||
|
@@ -84,7 +81,7 @@ module.exports = (dest, opts) => { | |
} | ||
} | ||
|
||
opts.hasChanged(this, cb, file, newPath); | ||
opts.hasChanged(this, file, newPath).then(() => cb()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can now move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! Thank you, and sorry for doing this line by line! Will do in 20 |
||
}); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is okay, but after Promise we run cb() either way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. You still need to pass the file down the stream even though its contents is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, thanks! Fixed it now.