Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed Oct 9, 2024
1 parent ef3a5eb commit 660eb13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,6 @@ fn copy_metadata(src: &Path, dest: &Path, src_metadata: &fs::Metadata) -> io::Re
let permissions = src_metadata.permissions();
fs::set_permissions(dest, permissions)?;

// Copy xattrs
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
fsxattr::copy_xattrs(src, dest)?;

// Copy ownership (if on Unix-like system)
#[cfg(unix)]
{
Expand All @@ -1036,18 +1032,23 @@ fn copy_metadata(src: &Path, dest: &Path, src_metadata: &fs::Metadata) -> io::Re
level: VerbosityLevel::Silent,
},
)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
.ok();
}

// Copy the modified and accessed timestamps
let modified_time = src_metadata.modified()?;
let accessed_time = src_metadata.accessed()?;
if dest_metadata.is_symlink() {
set_symlink_file_times(dest, accessed_time.into(), modified_time.into())?;
set_symlink_file_times(dest, accessed_time.into(), modified_time.into()).ok();

Check warning on line 1042 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L1042

Added line #L1042 was not covered by tests
} else {
set_file_times(dest, accessed_time.into(), modified_time.into())?;
set_file_times(dest, accessed_time.into(), modified_time.into()).ok();
}

// Copy xattrs.
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
fsxattr::copy_xattrs(src, dest)
.map_err(|err| show_error!("{err}"))

Check warning on line 1050 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L1050

Added line #L1050 was not covered by tests
.ok();
Ok(())
}

Expand Down
16 changes: 15 additions & 1 deletion tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,8 @@ mod inter_partition_copying {
use super::*;
use crate::common::util::TestScenario;
use std::ffi::OsString;
use std::fs::{read_to_string, set_permissions, write};
use std::fs::{read_to_string, set_permissions, write, File};
use std::io;
use std::os::unix::fs::{symlink, FileTypeExt, MetadataExt, PermissionsExt};
use tempfile::TempDir;
use uucore::display::Quotable;
Expand Down Expand Up @@ -1947,6 +1948,19 @@ mod inter_partition_copying {
// create a folder in another partition.
let other_fs_tempdir =
TempDir::new_in("/dev/shm/").expect("Unable to create temp directory");

let mut dest_fs_xattr_support = true;
let tempfile_path = other_fs_tempdir.path().join("temp_file");
let tf = File::create(&tempfile_path).expect("couldn't create tempfile");
if let Err(err) = tf.set_xattr(test_attr, test_value) {
if err.kind() == io::ErrorKind::Unsupported {
dest_fs_xattr_support = false;

Check warning on line 1957 in tests/by-util/test_mv.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_mv.rs#L1957

Added line #L1957 was not covered by tests
}
}
if !dest_fs_xattr_support {
println!("no fs xattr support");

Check warning on line 1961 in tests/by-util/test_mv.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_mv.rs#L1961

Added line #L1961 was not covered by tests
}

// make sure to wait for a second so that when the dest file is created, it
// would have a different filetime so that the only way the dest file
// would have a same timestamp is by copying the timestamp of src file.
Expand Down

0 comments on commit 660eb13

Please sign in to comment.