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

Read the target path of a symbolic link #132

Closed
maxthoursie opened this issue Aug 4, 2024 · 2 comments
Closed

Read the target path of a symbolic link #132

maxthoursie opened this issue Aug 4, 2024 · 2 comments

Comments

@maxthoursie
Copy link

It doesn't seem to be a way, without using java interop, of reading the target of a symlink if that target does not exist.

  (def source (fs/path "source"))
  (def target (fs/path "target"))  ;; Does not exist
  (fs/create-sym-link source target)

  ;; Wanted result, but using java interop
  (fs/file-name (java.nio.file.Files/readSymbolicLink source)) ; => "bar"

  ;; Failed attemptes
  (fs/file-name (fs/canonicalize source)) ; => "source"
  (fs/file-name (fs/canonicalize source {:nofollow-links true})) ; => "source"
  (fs/file-name (fs/real-path source)) ; NoSuchFileException
  (fs/file-name (fs/real-path source {:nofollow-links true})) ; => "source" 

  ;; Works if file exists
  (fs/create-file target)
  (fs/file-name (fs/canonicalize source)) ; => "target"
  (fs/file-name (fs/real-path source)) ; => "target"
@maxthoursie
Copy link
Author

In unix it's called readlink

$ readlink source
target

Node calls it readlink too

> fs.readlink("source", console.log)
undefined
> null target 

@borkdude
Copy link
Contributor

borkdude commented Aug 4, 2024

alright, fs/read-link seems like a good candidate name then

borkdude added a commit that referenced this issue Aug 5, 2024
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

2 participants