Skip to content
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

fs: do bulk file reads to optimize cache extraction #3539

Merged
merged 2 commits into from
May 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,39 +520,32 @@ export async function copyBulk(
}

const cleanup = () => delete currentlyWriting[data.dest];
return (currentlyWriting[data.dest] = new Promise((resolve, reject) => {
const readStream = fs.createReadStream(data.src);
const writeStream = fs.createWriteStream(data.dest, {mode: data.mode});

reporter.verbose(reporter.lang('verboseFileCopy', data.src, data.dest));

readStream.on('error', reject);
writeStream.on('error', reject);

writeStream.on('open', function() {
readStream.pipe(writeStream);
});

writeStream.once('close', function() {
fs.utimes(data.dest, data.atime, data.mtime, function(err) {
if (err) {
reject(err);
} else {
events.onProgress(data.dest);
cleanup();
resolve();
}
reporter.verbose(reporter.lang('verboseFileCopy', data.src, data.dest));
return (currentlyWriting[data.dest] = readFileBuffer(data.src)
.then(d => {
return writeFile(data.dest, d, {mode: data.mode});
})
.then(() => {
return new Promise((resolve, reject) => {
fs.utimes(data.dest, data.atime, data.mtime, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
});
})
.then(arg => {
cleanup();
return arg;
})
.catch(arg => {
cleanup();
throw arg;
}));
.then(
() => {
events.onProgress(data.dest);
cleanup();
},
err => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version seems to swallow the error while the original version would re-throw it after the cleanup(). Am I mis-reading this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you read that right. That's my mistake. Fixed 😁

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also dropped the forwarding of the resolved value in the resolve handler. Maybe it's not actually used anyway?

cleanup();
throw err;
},
));
},
CONCURRENT_QUEUE_ITEMS,
);
Expand Down