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

Support symlink creation #391

Open
jelly opened this issue Apr 23, 2024 · 7 comments
Open

Support symlink creation #391

jelly opened this issue Apr 23, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@jelly
Copy link
Member

jelly commented Apr 23, 2024

Our current implementation is an arbitrary symlink creation dialog

image

The target path can be edited to something else and is shown as an absolute path while the link name can't be an absolute path by only relative. (As the dialog prefills /home/admin).

This is confusing, because it made me think I should provide an absolute path in both inputs.

Symlink creation arbitrary creates a symlink under directory if directory is passed

image

Moving symlinks

Moving relative existing symlinks can break, do we show a warning?

@jelly jelly added the bug Something isn't working label Apr 23, 2024
@jelly jelly added this to the First official release milestone Apr 23, 2024
@jelly
Copy link
Member Author

jelly commented Apr 23, 2024

Some more questions:

  • Do we want to support relative symlinks? I am thinking we should not and treat this as a file manager. You make a link to something and then move this somewhere else.

@garrett
Copy link
Member

garrett commented Apr 24, 2024

Here's a comparison of all the sorts of links:

  • absolute symlinks:
    • when the source is at a particular unchanging place and you want to reference it
    • moving the source (even renaming a parent directory) breaks the destination
    • useful for referring to system files
    • refers to the complete path, starting from /
  • relative symlink:
    • when the source and destination are contained within the same parent directory
    • changing the parent of both source and destination does not break the link
    • useful for a project directory
    • relative path and may include parent directories as well "../", "../../", etc.
  • hardlink
    • a copy of the reference to a data on disk (inode)
    • moving source and/or destination does not break the link
    • they're both files that point to the same data on disk
    • only works for files, not directories
    • deleting one file doesn't delete the data (until all are deleted)
    • when you edit, you're editing the data that the hardlink points to, so all "files" change their contents
    • can't be across filesystems
  • reflink
    • similar to hardlink
    • when you edit a file that's a reflink, the content diverges between the two "files"
    • can't be across filesystems
    • only supported by some filesystems (btrfs, zfs, apfs, newer versions of xfs)
    • most copy commands now default to a reflink where supported

The important part is intent. Absolute is for referring to files outside of a project that will not move, whereas relative is for within self-contained directory trees (such as projects, git checkouts, etc.), which could possibly be reparented (renaming or moving the toplevel container directory). They're both valid uses of symlinks, and depending on what an administrator is using, they may want one or the other.

I guess we should probably show them untruncated and relative (so someone could see the actual files and path fragments that matter) and perhaps have an option to make it an absolute link in the background.

I'm not sure if hardlinks really make sense. I think they probably do not.

Reflinks, we get for free with a standard copy when on supported filesystems.

@garrett
Copy link
Member

garrett commented Apr 24, 2024

Taken all of the above into consideration, it looks like I need to design a new link modal.

We could put that on pause on the dialog for now and make linking make a "Link to" prefixed link like in GNOME.

However, I guess that would imply that it's an absolute link or some relative one that "smartly" updates when moved (which means we'd need to look at what the link links to and update it in the new location). The absolute link would be much easier to implement, even if it's less useful in most cases.

From https://stackoverflow.com/questions/8523159/how-do-i-move-a-relative-symbolic-link#8523293:

You can turn relative paths into full paths using readlink -f foo. So you would do something like:

ln -s $(readlink -f $origlink) $newlink
rm $origlink

and:

I noticed that you wish to keep the paths relative. In this case, after you move the link, you can use symlinks -c to convert the absolute paths back into relative paths.

...But this requires a command from the symlinks package, at least on Fedora, so it's out.

Someone in the thread mentioned this ln command as an alternative, which converts an absolute symlink to a relative one (by overwriting the absolute link with a relative one):

ln -srf $newlink

I don't see a way to do the opposite (relative to absolute), however, aside from the code block above.

So, moving/renaming a relative link could be:

  1. convert to absolute link
  2. do the move/rename
  3. convert back to relative link

However, it's more complex than just moving an absolute link.

(I wonder if Nautilus handles this? Edit: Nope, it does not properly handle moving symlinks separate from moving origin files, apparently.)

@jelly
Copy link
Member Author

jelly commented Apr 30, 2024

In my opinion we should make a "create link" context menu item which makes a link for a directory or file "Link to X" which would be an absolute symlink.

If the link already exists, either we don't show the context menu or overwrite or append (n).

@allisonkarlitskaya
Copy link
Member

I don't think we should have a UI option to create symlinks.

@jelly jelly changed the title Symlink creation issues Support symlink creation Apr 30, 2024
@jelly jelly removed this from the First official release milestone Apr 30, 2024
@jelly
Copy link
Member Author

jelly commented Apr 30, 2024

We concluded to drop symlink creation for now and we will re-visit this functionality later #419

@allisonkarlitskaya
Copy link
Member

I don't think we should have a UI option to create symlinks.

I think I retract this opinion. Some of our users expect this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants