readLink
builtin #656
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
ux
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#656
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
I wanted to figure out if a symlink is a directory or a file, so i can either run
builtins.readFile
orbuiltins.readDir
.I found no way to solve this as the symlink is detected as "symlink" by
builtins.readFileType
and there is no way to find out the symlink target.Describe the solution you'd like
Easy and simple a
readLink
that returns the content of the symlink.Handling the relativeness of that symlink or the possibility of danglinglyness would then be handled with other functions like
builtins.pathExists
.Describe alternatives you've considered
A
readLink
that errors on dangling symlinks and returns the resolved path to the original location.This issue was mentioned on Gerrit on the following CLs:
figuring out whether a symlink points to a directory or not can be done by appending a
/
to the path andpathExists
ing that extended path. adding a readlink function seems misguided because it doesn't tell you very useful for your specific question; absolute links will be broken in restricted/flake eval and relative links working depends greatly on how the path they are in is being accessed.unfortunately the current filesystem access situation is mondo messy, and unless there's a real need for this we probably shouldn't be adding more things that are subtly inconsistent :/
paths cannot have trailing slashes and if i do it as a string it doesn't work either
you're demonstrating exactly why we don't want to add this:
pathExists "${./testdirlink}/"
imports the link to the store—where it promptly breaks because it is relative and not rewritten by the import process. if you drop both of those files into a directory and import that via path literals it works, and likewise it works if you use absolute paths in unrestricted eval mode.filesystem handling is a gigantic mess currently, and solutions to that must be very well thought out (or we'll be stuck with another broken set of operations for the foreseeable future).
But
readLink ./testdirlink
, the way I have implemented it would not import the path to the store, would it?by itself, no. but if that snippet is run in flake context the link will still have been copied into the store, subject to VCS ignore rules.
if you just need to figure out whether a symlink points to a directory, `pointsToDir = x: builtins.pathExists "${toString x}/" is sufficient (and we can't even change that for something more sensible because that would explode nixpkgs)
oh, yeah it works with
toString
i still think a
readLink
builtin would be a good idea but i do agree that extending the, according to you, messy system is not worth it for this