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

fix: fix mtime precision on some filesystems #88

Merged
merged 1 commit into from Apr 3, 2019
Merged

Conversation

satazor
Copy link
Contributor

@satazor satazor commented Apr 2, 2019

Closes #82, #87

@satazor
Copy link
Contributor Author

satazor commented Apr 2, 2019

Tests still need to be updated!

@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #88 into master will increase coverage by 1.7%.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #88     +/-   ##
=======================================
+ Coverage   98.29%   100%   +1.7%     
=======================================
  Files           4      5      +1     
  Lines         176    192     +16     
  Branches       45     48      +3     
=======================================
+ Hits          173    192     +19     
+ Misses          3      0      -3
Impacted Files Coverage Δ
lib/lockfile.js 100% <100%> (+2.45%) ⬆️
lib/mtime-precision.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0cdea2...89d0749. Read the comment docs.

@satazor satazor force-pushed the mtime-precision branch 3 times, most recently from c9ff6b8 to 764be75 Compare April 3, 2019 10:56
@satazor
Copy link
Contributor Author

satazor commented Apr 3, 2019

I ended up changing the strategy to a more robust one.

After acquiring the lock, I will probe the precision of the filesystem passed in options.fs. This will do a extra utimes syscall when compared to what is in master. But the probing will be made only once and its value will be cached for the filesystem passed in options.fs.

This makes the code much more simple and easy to reason about.

@satazor
Copy link
Contributor Author

satazor commented Apr 3, 2019

@alanshaw @hugomrdias you may want to review this.

Copy link
Contributor

@hugomrdias hugomrdias left a comment

Choose a reason for hiding this comment

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

LGTM

let now = Date.now();

if (precision === 's') {
now = Math.ceil(now / 1000) * 1000;
Copy link
Contributor Author

@satazor satazor Apr 3, 2019

Choose a reason for hiding this comment

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

The fs might be either ceiling, rounding or flooring. ceil is preferred because of the isStaleLock check, where we are using a Date.now. This way, the mtime is always set a little bit in the future and the isStaleLock will always behave correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants