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

Test file copying preserves mtime #335

Closed
wants to merge 3 commits into from

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Oct 15, 2024

Adds a test to ensure that a file copied via the AppCache feature preserves the file's original mtime.

In #302 I determined that as long as the files copied into the cache dir preserve the original mtime then the FIFO cache cleaning logic that we rely on is valid. This test closes out this comment that asserted we need to verify whether or not the buildpack preserved mtime when copying files #302 (comment).

#close 302


Commits are in historical order. I'm interested in feedback regarding tests, possibly some edge cases I've overlooked regarding test cases. app_cache.rs is approx 213 lines without comments or tests.

Adds a test to ensure that a file copied via the AppCache feature preserves the file's original mtime. 


In #302 I determined that as long as the files copied into the cache dir preserve the original mtime then the FIFO cache cleaning logic that we rely on is valid. This test closes out this comment that asserted we need to verify whether or not the buildpack preserved mtime when copying files #302 (comment).


[#close 302]
@schneems schneems force-pushed the schneems/assert-mtime-preserved-when-copying branch from a6f802d to 77fca26 Compare October 15, 2024 21:32
Assert that loading from cache does not over-write files.
I previously introduced a commit that had a test intended to prove that we were persisting the mtime of files copied into the cache to close out this comment #302 (comment). The test passed locally, but failed on CI.

It appears the behavior of fs-extra with regards to mtime for copying/moving directories is system dependent. To compensate, I switched to `cp_r` which explicitly is designed to preserve mtime https://crates.io/crates/cp_r. It has ~27,000 lifetime downloads and has activity as recently as a 9 days ago. https://docs.rs/cp_r/latest/cp_r/#release-history

Copying and preserving mtime is the primary reason this library exists. From the docs.rs:

> Copy a directory tree, including mtimes and permissions.

It does not have the ability to skip-overwriting existing files which I need, however it has a generic `filter` closure which allows me to assemble this behavior myself.

store.load().unwrap();

let metadata = fs_err::metadata(store.cache.join("lol.txt")).unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be store.path and not store.cache

@schneems
Copy link
Contributor Author

Cleaned up and re-opened #336

@schneems schneems closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant