Skip to content
Closed
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: 9 additions & 2 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.map(|v| v.map(PathBuf::from).collect())
.unwrap_or_default();

let (sources, target) = parse_path_args(paths, &options)?;
let (sources, target) = parse_path_args(paths, &options)?; //

if let Err(error) = copy(&sources, &target, &options) {
match error {
Expand Down Expand Up @@ -1399,6 +1399,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
{
// There is already a file and it isn't a symlink (managed in a different place)
if copied_destinations.contains(&dest) && options.backup != BackupMode::Numbered {
// NOT IN HERE
// If the target was already created in this cp call, check if it's a directory.
// Directories should be merged (GNU cp behavior), but files should not be overwritten.
let dest_is_dir = fs::metadata(&dest).is_ok_and(|m| m.is_dir());
Expand Down Expand Up @@ -1517,6 +1518,7 @@ fn copy_source(
)
} else {
// Copy as file
// HERE
let dest = construct_dest_path(source_path, target, target_type, options)?;
let res = copy_file(
progress_bar,
Expand Down Expand Up @@ -2143,6 +2145,7 @@ fn handle_copy_mode(
created_parent_dirs: &mut HashSet<PathBuf>,
#[cfg(unix)] source_is_stream: bool,
) -> CopyResult<PerformedAction> {
// Need to put perms in here
let source_is_symlink = source_metadata.is_symlink();

match options.copy_mode {
Expand Down Expand Up @@ -2483,6 +2486,7 @@ fn copy_file(
err.to_string()
})?
};
dbg!(&source_metadata); // This contains the perms

let dest_metadata = dest.symlink_metadata().ok();

Expand All @@ -2493,6 +2497,7 @@ fn copy_file(
options,
context,
)?;
dbg!(&dest_permissions);

#[cfg(unix)]
let source_is_fifo = source_metadata.file_type().is_fifo();
Expand Down Expand Up @@ -2532,7 +2537,7 @@ fn copy_file(
//
// FWIW, the OS will throw an error later, on the write op, if
// the user does not have permission to write to the file.
fs::set_permissions(dest, dest_permissions).ok();
// fs::set_permissions(dest, dest_permissions).ok();
}

if options.dereference(source_in_command_line) {
Expand Down Expand Up @@ -2649,6 +2654,7 @@ fn copy_helper(
created_parent_dirs: &mut HashSet<PathBuf>,
#[cfg(unix)] source_is_stream: bool,
) -> CopyResult<()> {
dbg!("We get here");
if options.parents {
let parent = dest.parent().unwrap_or(dest);
if created_parent_dirs.insert(parent.to_path_buf()) {
Expand All @@ -2669,6 +2675,7 @@ fn copy_helper(
} else if source_is_symlink {
copy_link(source, dest, symlinked_files, options)?;
} else {
dbg!("and here");
let copy_debug = copy_on_write(
source,
dest,
Expand Down
11 changes: 10 additions & 1 deletion src/uu/cp/src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ fn clone<P>(source: P, dest: P, fallback: CloneFallback) -> std::io::Result<()>
where
P: AsRef<Path>,
{
dbg!("THE CREATION BEGINS");
let src_file = File::open(&source)?;
let dst_file = File::create(&dest)?;
dbg!("dest");
// Use open options to allow us to set the mode of the file
let dst_file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.mode(0o600)
.open(&dest)?;
let src_fd = src_file.as_raw_fd();
let dst_fd = dst_file.as_raw_fd();
let result = unsafe { libc::ioctl(dst_fd, libc::FICLONE, src_fd) };
Expand Down Expand Up @@ -270,6 +278,7 @@ pub(crate) fn copy_on_write(
reflink: OffloadReflinkDebug::Unsupported,
sparse_detection: SparseDebug::No,
};
dbg!(&reflink_mode, &sparse_mode);
let result = match (reflink_mode, sparse_mode) {
(ReflinkMode::Never, SparseMode::Always) => {
copy_debug.sparse_detection = SparseDebug::Zeros;
Expand Down
Loading