Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory copy different behavior #50

Open
alekspickle opened this issue Sep 29, 2021 · 0 comments
Open

Directory copy different behavior #50

alekspickle opened this issue Sep 29, 2021 · 0 comments

Comments

@alekspickle
Copy link

alekspickle commented Sep 29, 2021

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?

@alekspickle alekspickle changed the title Derectory copy different behavior Directory copy different behavior Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant