fs_extra icon indicating copy to clipboard operation
fs_extra copied to clipboard

Directory copy different behavior

Open olekspickle opened this issue 3 years ago • 0 comments

Hey! Thx for lib, but I have noticed that directory copy behaves in non-idempotent way.

Suppose we have:

let pathbufs = [PathBuf::from("directory1"), PathBuf::from("directory2"), PathBuf::from("directory3")];
let options = fs_extra::dir::CopyOptions {
        overwrite: true,
        copy_inside: true,
        ..Default::default()
    };
let to = PathBuf::new("current");

    for p in pathbufs {
        if let Err(e) = fs_extra::dir::copy(&p, &to, &options) {
            eprintln!(
                "Failed to copy directory: {:?} path: {}",
                e,
                p.display()
            );
        }
    }

First time running copying content of the directory1 in the root of the current path, and the second time it works as I want - I have all 3 dirs there but with directory1 files from previous run. Is there a way to copy all 3 directories if there are no current/ directory created previously?

Result after 1st run:

current/
|-- file1.txt
|-- file11.txt
|-- directory2
|   |-- ...
|-- directory3
`   |--...


Result after 2nd run

current/
|-- directory1
|   |-- file1.txt
|   `-- file11.txt
|-- file1.txt
|-- file11.txt
|-- directory2
|   |-- ...
|-- directory3
`   |--...


I understand that this is exactly the behavior of cp -r on Linux, but maybe there could be a flag for this case?

olekspickle avatar Sep 29 '21 14:09 olekspickle