Skip to content

Commit

Permalink
Test file copying preserves mtime
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
schneems committed Oct 15, 2024
1 parent cc50d62 commit 77fca26
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions buildpacks/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ toml = "0.8"

[dev-dependencies]
libcnb-test = "=0.23.0"
filetime = "0.2.25"
3 changes: 3 additions & 0 deletions buildpacks/ruby/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ mod user_errors;
#[cfg(test)]
use libcnb_test as _;

#[cfg(test)]
use filetime as _;

use clap as _;

struct RubyBuildpack;
Expand Down
31 changes: 31 additions & 0 deletions commons/src/cache/app_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,35 @@ mod tests {
assert!(store.cache.join("lol.txt").exists());
assert!(!store.path.join("lol.txt").exists());
}

#[test]
fn mtime_preserved() {
let tmpdir = tempfile::tempdir().unwrap();
let cache_path = tmpdir.path().join("cache");
let app_path = tmpdir.path().join("app");

fs_err::create_dir_all(&cache_path).unwrap();
fs_err::create_dir_all(&app_path).unwrap();

let store = AppCache {
path: app_path.clone(),
cache: cache_path,
limit: Byte::from_u64(512),
keep_path: KeepPath::BuildOnly,
cache_state: CacheState::NewEmpty,
};

let mtime = filetime::FileTime::from_unix_time(1000, 0);

let path = app_path.join("lol.txt");
fs_err::write(&path, "hahaha").unwrap();
filetime::set_file_mtime(&path, mtime).unwrap();

store.save().unwrap();

let metadata = fs_err::metadata(store.cache.join("lol.txt")).unwrap();
let actual = filetime::FileTime::from_last_modification_time(&metadata);

assert_eq!(mtime, actual);
}
}

0 comments on commit 77fca26

Please sign in to comment.