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

Errors with recursive cp with S3Paths #225

Open
ericphanson opened this issue Nov 16, 2021 · 0 comments
Open

Errors with recursive cp with S3Paths #225

ericphanson opened this issue Nov 16, 2021 · 0 comments

Comments

@ericphanson
Copy link
Member

If src has nested directories and the dst is an S3Path, we get errors since we are missing final /s when we readdir a local directory and get the names.

We could modify cp to insert /s as needed:

function Base.cp(src::AbstractPath, dst::AbstractPath; force=false, follow_symlinks=false)
    if exists(dst)
        if force
            rm(dst; force=force, recursive=true)
        else
            throw(ArgumentError("Destination already exists: $dst"))
        end
    end

    if !exists(src)
        throw(ArgumentError("Source path does not exist: $src"))
    elseif isdir(src)
        mkdir(dst)

        for fp in readdir(src)
            src_fp = src / fp
            dst_fp = dst / fp
            if isdir(src_fp) && !endswith(dst_fp, "/")
                dst_fp *= "/"
            end
            cp(src_fp, dst_fp; force=force)
        end
    elseif isfile(src)
        write(dst, read(src))
    elseif islink(src)
        follow_symlinks ? symlink(readlink(src), dst) : write(dst, read(FilePathsBase.canonicalize(src)))
    else
        throw(ArgumentError("Source path is not a file or directory: $src"))
    end

    return dst
end

Transferred from rofinn/FilePathsBase.jl#128

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