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: fix bug #1823 #1848

Merged
merged 6 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 18 additions & 11 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,25 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &PathBuf, b: &Behavior) ->

let mut all_successful = true;
for sourcepath in files.iter() {
let targetpath = match sourcepath.as_os_str().to_str() {
Some(name) => target_dir.join(name),
None => {
show_error!(
"cannot stat '{}': No such file or directory",
sourcepath.display()
);
if !sourcepath.exists() {
show_error!(
"cannot stat '{}': No such file or directory",
sylvestre marked this conversation as resolved.
Show resolved Hide resolved
sourcepath.display()
sylvestre marked this conversation as resolved.
Show resolved Hide resolved
);

all_successful = false;
continue;
}
};
all_successful = false;
continue;
}

if sourcepath.is_dir() {
show_info!("omitting directory '{}'", sourcepath.display());
all_successful = false;
continue;
}

let mut targetpath = target_dir.clone().to_path_buf();
let filename = sourcepath.components().last().unwrap();
targetpath.push(filename);

if copy(sourcepath, &targetpath, b).is_err() {
all_successful = false;
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,21 @@ fn test_install_target_file_dev_null() {
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
assert!(at.file_exists(file2));
}

#[test]
fn test_install_copy_file_leading_dot() {
let (at, mut ucmd) = at_and_ucmd!();
let dir1 = "test_install_target_new_file_dir_l";
let dir2 = "test_install_target_new_file_dir_m";
let file1 = "test_install_target_file_file_l1";

at.mkdir(dir1);
at.mkdir(dir2);
at.touch(&format!("{}/{}", dir1, file1));

ucmd.arg(format!("{}/{}", dir1, file1))
.arg(dir2)
.succeeds()
.no_stderr();
assert!(at.file_exists(&format!("{}/{}", dir2, file1)));
}