coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

cp: 'cp foo foo' with backup should not fail

Open sylvestre opened this issue 3 years ago • 2 comments

Should fix tests/cp/backup-1.sh

sylvestre avatar Apr 18 '22 21:04 sylvestre

Warning: Congrats! The gnu test tests/cp/backup-1 is no longer failing!

sylvestre avatar Apr 19 '22 06:04 sylvestre

Code looks good, but the test seems to be a bit flaky on mac and windows.

tertsdiepraam avatar Apr 19 '22 16:04 tertsdiepraam

What was the status on this one? This merge conflict seems to imply that it has already been fixed, right? Both versions have the options.backup == BackupMode::NoBackup check and cp/backup-1 is passing in coreutils-tracking.

<<<<<<< cp-same
fn handle_existing_dest(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
    if paths_refer_to_same_file(source, dest)? && options.backup == BackupMode::NoBackup {
        return Err(format!("{}: same file", context_for(source, dest)).into());
=======
/// Decide whether source and destination files are the same and
/// copying is forbidden.
///
/// Copying to the same file is only allowed if both `--backup` and
/// `--force` are specified and the file is a regular file.
fn is_forbidden_copy_to_same_file(
    source: &Path,
    dest: &Path,
    options: &Options,
    source_in_command_line: bool,
) -> bool {
    // TODO To match the behavior of GNU cp, we also need to check
    // that the file is a regular file.
    let dereference_to_compare =
        options.dereference(source_in_command_line) || !source.is_symlink();
    paths_refer_to_same_file(source, dest, dereference_to_compare)
        && !(options.force() && options.backup != BackupMode::NoBackup)
}

tertsdiepraam avatar Nov 13 '22 11:11 tertsdiepraam

I think it can be closed as already fixed because of pull request #3966.

jfinkels avatar Nov 19 '22 14:11 jfinkels