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

Open
#187 4 comments 0 reactions 0 assignees View on GitHub

@shivampwm2020 is already working on this.

Since Oct 15, 2026.

  • #286 by @shivampwm2020 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
clojure
Domain
tooling

Research direction

Start with the copy-tree entry point and run the Clojure reproduction from the issue, comparing the follow-links and nofollow-links behavior. Done means copying with default link following produces link-bar with the same nested contents as bar, while nofollow-links continues to preserve the symbolic link.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Clojure
Stars
221
Forks
52
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from babashka/fs

All issues in babashka/fs

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.