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

install: with -t, check if we aren't passed a file #5686

Merged
merged 1 commit into from
Dec 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/uu/install/src/install.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

There is one situation not handled by this solution: if the target ends with a slash. With GNU, install -t sub/b -Dv a and install -t sub/b/ -Dv a both lead to the same error. With uutils, install -t sub/b/ -Dv a shows a "creating directory" message followed by a "failed to create" message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel that it is a different problem in this case, no ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, though it is related. We can fix it in another PR.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
InvalidUser(String),
InvalidGroup(String),
OmittingDirectory(PathBuf),
NotADirectory(PathBuf),

Check warning on line 69 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L69

Added line #L69 was not covered by tests
}

impl UError for InstallError {
Expand Down Expand Up @@ -120,6 +121,9 @@
Self::InvalidUser(user) => write!(f, "invalid user: {}", user.quote()),
Self::InvalidGroup(group) => write!(f, "invalid group: {}", group.quote()),
Self::OmittingDirectory(dir) => write!(f, "omitting directory {}", dir.quote()),
Self::NotADirectory(dir) => {
write!(f, "failed to access {}: Not a directory", dir.quote())
}
}
}
}
Expand Down Expand Up @@ -583,6 +587,13 @@
}
}
}
if b.target_dir.is_some() {
let p = to_create.unwrap();

if !p.exists() || !p.is_dir() {
return Err(InstallError::NotADirectory(p.to_path_buf()).into());
}
}
}

if sources.len() > 1 || is_potential_directory_path(&target) {
Expand Down
24 changes: 24 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,3 +1538,27 @@ fn test_install_compare_option() {
.code_is(1)
.stderr_contains("Options --compare and --strip are mutually exclusive");
}

#[test]
// Matches part of tests/install/basic-1
fn test_t_exist_dir() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

let source1 = "file";
let target_dir = "sub4/";
let target_file = "sub4/file_exists";

at.touch(source1);
at.mkdir(target_dir);
at.touch(target_file);

scene
.ucmd()
.arg("-t")
.arg(target_file)
.arg("-Dv")
.arg(source1)
.fails()
.stderr_contains("failed to access 'sub4/file_exists': Not a directory");
}
Loading