Skip to content

Conversation

@zxvfc
Copy link
Contributor

@zxvfc zxvfc commented Dec 4, 2025

This PR removes leading slash from file names if path is absolute.

Closes: #44

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (b55f085) to head (7ec4f19).
⚠️ Report is 42 commits behind head on main.

Additional details and impacted files
@@    Coverage Diff     @@
##   main   #53   +/-   ##
==========================
==========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@stillbeingnick stillbeingnick left a comment

Choose a reason for hiding this comment

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

Good stuff! But we also need to make sure we normalize dir paths and file paths. Both BSD and GNU tar strip leading '/' on paths for dirs and files.

Rework normalize_name to return
Copy link

@stillbeingnick stillbeingnick left a comment

Choose a reason for hiding this comment

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

Awesome! So this has the knock on effect of mirroring gnu and bsd that displays the "removing leading ..." message for each dir that needs to to be stripped.

@zxvfc
Copy link
Contributor Author

zxvfc commented Dec 17, 2025

Hi @stillbeingnick! What do you think, does it make sense to add a test for that feature too?

@stillbeingnick
Copy link

Hi @stillbeingnick! What do you think, does it make sense to add a test for that feature too?

Yes testing is always the way to go @zxvfc 👍 Adding a new test in tar/tests/by-util/test_tar.rs called something like test_create_from_dir() This can test creation of an archive using a dir, and the verbose option listing files in the dir. Then adding an additional test called something like test_create_absolute_path() that for right now ensures we are stripping leading slashes on absolutes, later on can test both stripping and leaving alone with the -P option.

@zxvfc zxvfc requested a review from stillbeingnick December 18, 2025 09:00
Copy link

@stillbeingnick stillbeingnick left a comment

Choose a reason for hiding this comment

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

Minor things, 1 test name change and splitting 1 test apart (creating and extracting absolute path) for some better unit coverage. Right now we are really laying foundational things and I want our Tar to be built on concrete and not sand, so I really appreciate the participation, refactoring, and willingness!

Comment on lines 101 to 110
new_ucmd!()
.args(&["-xf", "archive.tar"])
.current_dir(at.as_string())
.succeeds();

let expected_path = format!(
"{}{separator}{file_name}",
abs_path.strip_prefix(separator).unwrap()
);
assert!(at.file_exists(expected_path));

Choose a reason for hiding this comment

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

I appreciate the thoroughness of the test! But we need to break this out to another test since Creating and Extracting are two different operations. I want to try to keep testing separated at least for now by main operation modes. We will end up repeating some boilerplate for the testing (ie. creating the archive so we can extract it) but we can abstract and create correct dependencies in testing once the main operations modes are in place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, sounds reasonable. Split now!

Comment on lines 36 to 56
fn test_verbose() {
let (at, mut ucmd) = at_and_ucmd!();

let separator = path::MAIN_SEPARATOR;
let dir1_path = "dir1";
let dir2_path = format!("{dir1_path}{separator}dir2");
let file1_path = format!("{dir1_path}{separator}file1.txt");
let file2_path = format!("{dir2_path}{separator}file2.txt");

at.mkdir(dir1_path);
at.mkdir(&dir2_path);
at.write(&file1_path, "test content 1");
at.write(&file2_path, "test content 2");

ucmd.args(&["-cvf", "archive.tar", dir1_path])
.succeeds()
.stdout_contains(dir1_path)
.stdout_contains(dir2_path)
.stdout_contains(file1_path)
.stdout_contains(file2_path);
}

Choose a reason for hiding this comment

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

Okay one this is very concise and well done so 🥇 great job. Small nit to pick lets change the name of this test to something like test_create_dir_verbose(). This way we know exactly what it is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed!

@zxvfc zxvfc requested a review from stillbeingnick December 19, 2025 09:27
Copy link

@stillbeingnick stillbeingnick left a comment

Choose a reason for hiding this comment

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

Awesome stuff! Thank you for making the changes it will really help in the long term! LGTM 👍

@zxvfc
Copy link
Contributor Author

zxvfc commented Dec 20, 2025

@stillbeingnick, awesome! Thank you so much for the review and guidance, I really appreciate it.

Shall we now close and merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When creating an archive, remove leading slashes from filename

2 participants