Skip to content

copy-tree, when following links, does not copy contents of symbolicly linked sub-dir #187

@lread

Description

@lread

Issue

When asked to follow links, copy-tree copies symbolically linked subdirs, but not their content.

Repro

Setup scenario

(fs/create-dirs "src-dir/bar/baz")
(spit "src-dir/bar/baz/somefile.txt" "bippity boo")
(fs/create-sym-link "src-dir/link-bar" "bar")

We have:

└── src-dir/
    ├── bar/
    │   └── baz/
    │       └── somefile.txt
    └── link-bar -> bar/

Perform copy-tree (which currently follows symbolic links by default):

(fs/copy-tree "src-dir" "dest-dir")

We now have:

├── dest-dir/
│   ├── bar/
│   │   └── baz/
│   │       └── somefile.txt
│   └── link-bar/
└── src-dir/
    ├── bar/
    │   └── baz/
    │       └── somefile.txt
    └── link-bar -> bar/

Notice that link-bar/ is copied as a dir but there is nothing underneath it.

Expected Behaviour

Shouldn't dest-dir/link-bar/ have the same subdirs as dest-dir/bar?

Explore

What happens when we don't follow links?

(fs/copy-tree "src-dir" "dest-dir-nf" {:nofollow-links true})

Gives us:

dest-dir-nf/
├── bar/
│   └── baz/
│       └── somefile.txt
└── link-bar -> bar/

This seems correct.

What does cp do?

Let's compare with an equivalent cp that follows links:

$ cp -r --dereference src-dir dest-dir-cp
$ tree -F dest-dir-cp
dest-dir-cp/
├── bar/
│   └── baz/
│       └── somefile.txt
└── link-bar/
    └── baz/
        └── somefile.txt

Notice that link-bar/, unlike copy-tree, has the same contents as bar/.

And what about a cp that does not follow links:

$ cp -r src-dir dest-dir-cp-nf
$ tree -F dest-dir-cp-nf
dest-dir-cp-nf/
├── bar/
│   └── baz/
│       └── somefile.txt
└── link-bar -> bar/

This matches copy-tree when not following links.

Next steps

Discuss, decide, make changes.

Happy to do up PR when we see the path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions