-
Notifications
You must be signed in to change notification settings - Fork 774
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
Add heuristics to stats.ino comparison when bigint is not available #694
Add heuristics to stats.ino comparison when bigint is not available #694
Conversation
10b96d3
to
bea4a39
Compare
Sorry about the last commit (10b96d3), I pushed too fast - it's unnecessary. I removed it. |
Checked the coverage loss - it's due to the fact that the code branch where I added the heuristic checks was not covered by tests (of course, since BigInt is supported in the test runs used by the coverage check). |
lib/util/stat.js
Outdated
throw new Error(errMsg(src, dest, funcName)) | ||
} | ||
return checkParentPathsSync(src, srcStat, destParent, funcName) | ||
} | ||
|
||
function areApparentlyIdentical (srcStat, destStat) { |
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.
This is good but the function name is a bit confusing. Will you please rename it to something simpler like just areIdentical
?
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.
Sure thing
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.
Fixed in 7e4c852
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! however this needs to be squashed before merging.
7e4c852
to
391fb73
Compare
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
I'm good with merging. |
The resolution of #657 relies on Node >= 10.5, but actually leaves the issue not fixed on previous versions of Node (in particular, for the OP, who reported the issue on Node 8.11.3). The issue particularly problematic and frequent in automated setups, such as running tests that create files in sequence, where it is likely to happen.
This PR minimizes the frequency of this issue by comparing additional
fs.Stats
values whenBigint
support is not available. Note that the check is still heuristic: different stats prove they are different files*, but while same stats do not prove they are the same, we must err on the side of caution and still treat them as the same file.(*) Race condition: comparing file stats before performing a copy or other operation implicitly introduces a race condition. However the existing implementation already suffered from this, so we presume that this PR does not make the condition much worse (with the exception that unlike
ino
andvol
, a malicious user could in theory manipulate some of the otherstats
). In practice, this race condition seems extremely hard to abuse, since it requires using a vulnerable system, and a means to change the file stats between the twostats
calls made bygetStats
andgetStatsSync
.