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 commented Apr 2, 2019

Closes #82, #87

@satazor

This comment has been minimized.

Copy link
Contributor Author

satazor commented Apr 2, 2019

Tests still need to be updated!

@satazor satazor force-pushed the mtime-precision branch 2 times, most recently from 6c258ef to a88b324 Apr 3, 2019
@codecov

This comment has been minimized.

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 Apr 3, 2019
@satazor

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

satazor commented Apr 3, 2019

@alanshaw @hugomrdias you may want to review this.

Copy link
Member

hugomrdias left a comment

LGTM

let now = Date.now();

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

This comment has been minimized.

Copy link
@satazor

satazor Apr 3, 2019

Author Contributor

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.

@satazor satazor force-pushed the mtime-precision branch from 764be75 to 8434729 Apr 3, 2019
Closes #82, #87
@satazor satazor force-pushed the mtime-precision branch from 8434729 to 89d0749 Apr 3, 2019
@satazor satazor merged commit f266158 into master Apr 3, 2019
4 checks passed
4 checks passed
codecov/patch 100% of diff hit (target 98.29%)
Details
codecov/project 100% (+1.7%) compared to c0cdea2
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@satazor satazor deleted the mtime-precision branch Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.