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

Add preserve option to cp #869

Merged
merged 9 commits into from Jan 27, 2022
Merged

Add preserve option to cp #869

merged 9 commits into from Jan 27, 2022

Conversation

nfischer
Copy link
Member

@nfischer nfischer commented Jul 4, 2018

This is a redo of #841.

This adds the -p flag to cp() to preserve certain attributes, such as timestamps.

Fixes #771

@nfischer
Copy link
Member Author

nfischer commented Jul 4, 2018

Work left:

  • the sleeps are misplaced. Remove them. Replace them with correct solution (use touch to modify source timestamps to something other than "now")
  • fix this for directories (that was never implemented)
  • add comments I requested in the original PR
  • documentation
  • investigate why cp -p modifies the atime of the source file

@nfischer nfischer added this to the v0.8.x milestone Jul 12, 2018
@nfischer nfischer removed this from the v0.8.x milestone Apr 6, 2021
Copy link

@monstrito monstrito left a comment

Choose a reason for hiding this comment

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

@maldito-dot
GET / HTTP/1.1
Accept: /
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: sessionid=foo;another-cookie=bar
Host: pie.dev
User-Agent: HTTPie/0.9.9

@nfischer
Copy link
Member Author

If anyone wants to take this over, help would be welcome! 🙏🏻

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2022

Codecov Report

Merging #869 (a72bc8c) into master (5d25e9b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #869      +/-   ##
==========================================
+ Coverage   97.18%   97.19%   +0.01%     
==========================================
  Files          36       36              
  Lines        1349     1354       +5     
==========================================
+ Hits         1311     1316       +5     
  Misses         38       38              
Impacted Files Coverage Δ
src/cp.js 91.53% <100.00%> (+0.33%) ⬆️

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 5d25e9b...a72bc8c. Read the comment docs.

This rewrites the `cp -p` tests to make some reasonable assertions about
the behavior. This also removes sleep statements. This leaves a TODO for
a known bug.
@nfischer
Copy link
Member Author

Hmm. There appears to be a node v9 bug which limits the resolution of atime/mtime to seconds (instead of milliseconds). I wonder if changing the test values from 12345 to 12345000 will work.

This works around a node v9 bug where mtime and atime appear to only
have precision in seconds even though the units are in milliseconds.
@nfischer
Copy link
Member Author

Blocked on #1074

Apparently `cp -p` actually does update the atime of the source file.
@nfischer
Copy link
Member Author

Actually... maybe cp -p is supposed to update the source file's atime. This behavior seems weird, but it seems to be how bash behaves.

This adds recursive support for `cp -p`. This also sets atime/mtime on
the directory itself.
@nfischer nfischer added this to the v0.9.0 milestone Jan 27, 2022
@nfischer nfischer added feature bash compat Compatibility issues with bash or POSIX behavior and removed blocked labels Jan 27, 2022
@nfischer nfischer merged commit 9a0e5f6 into master Jan 27, 2022
@nfischer nfischer deleted the feat-cp-preserve branch January 27, 2022 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash compat Compatibility issues with bash or POSIX behavior feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve timestamps on cp?
4 participants