coreutils
coreutils copied to clipboard
cp: 'cp foo foo' with backup should not fail
Should fix tests/cp/backup-1.sh
Warning: Congrats! The gnu test tests/cp/backup-1 is no longer failing!
Code looks good, but the test seems to be a bit flaky on mac and windows.
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)
}
I think it can be closed as already fixed because of pull request #3966.