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(cache): restoration symlink #7633

Merged
merged 3 commits into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/turborepo-cache/src/cache_archive/create.rs
Expand Up @@ -397,9 +397,11 @@ mod tests {
let mut archive = CacheWriter::create(&tar_path)?;
let base = "this-is-a-really-really-really-long-path-like-so-very-long-that-i-can-list-all-of-my-favorite-directors-like-edward-yang-claire-denis-lucrecia-martel-wong-kar-wai-even-kurosawa";
let file_name = format!("{base}.txt");
let dir_symlink_name = format!("{base}-dir");
let really_long_file = AnchoredSystemPath::new(&file_name).unwrap();
let really_long_dir = AnchoredSystemPath::new(base).unwrap();
let really_long_symlink = AnchoredSystemPath::new("this-is-a-really-really-really-long-symlink-like-so-very-long-that-i-can-list-all-of-my-other-favorite-directors-like-jim-jarmusch-michelangelo-antonioni-and-terrence-malick-symlink").unwrap();
let really_long_dir_symlink = AnchoredSystemPath::new(&dir_symlink_name).unwrap();

let really_long_path = archive_dir_path.resolve(really_long_file);
really_long_path.create_with_contents("The End!")?;
Expand All @@ -410,7 +412,11 @@ mod tests {
let really_long_dir_path = archive_dir_path.resolve(really_long_dir);
really_long_dir_path.create_dir_all()?;

let really_long_dir_symlink_path = archive_dir_path.resolve(really_long_dir_symlink);
really_long_dir_symlink_path.symlink_to_dir(really_long_dir.as_str())?;

archive.add_file(archive_dir_path, really_long_file)?;
archive.add_file(archive_dir_path, really_long_dir_symlink)?;
archive.add_file(archive_dir_path, really_long_dir)?;
archive.add_file(archive_dir_path, really_long_symlink)?;

Expand All @@ -421,10 +427,11 @@ mod tests {

let mut restore = CacheReader::open(&tar_path)?;
let files = restore.restore(restore_dir_path)?;
assert_eq!(files.len(), 3);
assert_eq!(files.len(), 4);
assert_eq!(files[0].as_str(), really_long_file.as_str());
assert_eq!(files[1].as_str(), really_long_dir.as_str());
assert_eq!(files[2].as_str(), really_long_symlink.as_str());
assert_eq!(files[3].as_str(), really_long_dir_symlink.as_str());
Ok(())
}

Expand Down
7 changes: 2 additions & 5 deletions crates/turborepo-cache/src/cache_archive/restore.rs
Expand Up @@ -124,14 +124,11 @@ impl<'a> CacheReader<'a> {
let mut nodes = HashMap::new();

for entry in symlinks {
let processed_name = AnchoredSystemPathBuf::from_system_path(&entry.header().path()?)?;
let processed_name = AnchoredSystemPathBuf::from_system_path(&entry.path()?)?;
let processed_sourcename =
canonicalize_linkname(anchor, &processed_name, processed_name.as_path())?;
// symlink must have a linkname
let linkname = entry
.header()
.link_name()?
.expect("symlink without linkname");
let linkname = entry.link_name()?.expect("symlink without linkname");

let processed_linkname = canonicalize_linkname(anchor, &processed_name, &linkname)?;

Expand Down