-
Notifications
You must be signed in to change notification settings - Fork 776
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
copySync, moveSync: remove extra step in reading loop #553
copySync, moveSync: remove extra step in reading loop #553
Conversation
I'm not understanding exactly why these changes are needed and what this fixes? |
let pos = 0 | ||
|
||
while (bytesRead > 0) { |
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.
@RyanZim bytesRead
will be greater than zero right after the file is copied.
At this moment pos === srcStat.size
and the next line will call fs.readSync
with this pos
as argument for position.
On my environment node throws error "ENOENT" if try to read file from position which greater than or equal to its size.
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.
LGTM
Nice work. Is it possible to get a test in place for at least one of these cases? Thanks. |
@jprichardson Cases I've mentioned are just for environment on our project and they already covered with existed tests. This MR is just for removing extra step in loop. |
By some reasons on our environment
fs.readSync
from node 8.x throws error when try to read data from position which more than size of file. Here is the test script with logs in comments:https://gist.github.com/wontem/da867f66324e1cbe712c717b5fefb944
Since we start using node 8.x and fs-extra 5.x - the issue is disappeared (fs-extra uses
copyFileSync
from node) but with node 8.x and fs-extra 3.0.1 the issue is reproducible.While investigating the problem I've noticed that the method
copySync
from fs-extra 3.0.1 uses extra step in its read loop. To be more safe I want to suggest remove this step from fallback logic forcopySync
and formoveSync
in fs-extra 5.x