Convert symlinks absolute to relative paths (SOLVED)


Recommended Posts

Hi Everybody!

 

Is there a good way in unraid to converst absolute path symlinks to relative path?

 

Some more context:

I would like to use folders/files with symlinks in a docker. However, the symlinks have absolute path, which won't work within docker, unless I give more broad permissions. Thus I would like to convert the existing symlings to relative path.

I can give the docker access to the actual (non symlink) files, but their folder structure is not useful in that docker context.

 

This tool seems to be perfect for the job, but not sure if it's even installable in unraid:

https://github.com/brandt/symlinks

 

Any thoughts on how to make this symlink tool work in unraid?

Any other ideas on how to convert the symlinks to relative path?

Thank you!

Edited by froland80
marking as solved
Link to comment

Thanks, @mgutt.

The docker can access the original files, but they are in an inconvenient file/folder structure.

Thus, I created a version with symlinks in a better structure.

The problem is that the symlinks are absolute path and the docker does not have access to all the parts of the absolute path. So, the docker can't resolve the links, even if it would have access to the files. ...at least that's what I understood from here.

 

So, relative links should make it work or did I miss anything?

 

This tool should do it, but unraid doesn't seem to have the "make" command to install/compile the tool. Can I just compile that on a mac and then transfer it over?

Link to comment
7 hours ago, froland80 said:

So, relative links should make it work or did I miss anything?

Yes, but only if the target path is inside of the mapped path.

 

Example:

/container/data maps to /host/data

 

Relative link:

image.jpg

 

Would target:

/container/data/image.jpg

which maps to:

/host/data/image.jpg

 

Would not work:

../images/image.jpg

 

Would target: 

/container/images/image.jpg

which maps to nothing (it stays inside the docker itself).

 

This would only work if you map /container/images to /host/images as well or if you would map /container to /host for much broader access to the host (which was done in the "Plex example").

 

Depending to your target it's maybe better to create hardlinks to all the files that should be accessible through the container. But note: hardlinks work only for files. But they allow the following:

 

/host/some_files/image.jpg links to /host/images/image.jpg

 

/host/some_files/texts/text.txt links to /host/texts/2021/01/28/text.txt

 

Now you map /host/some_files to the container and it can only access those files.

 

 

  • Thanks 1
Link to comment
2 hours ago, mgutt said:
10 hours ago, froland80 said:

So, relative links should make it work or did I miss anything?

Yes, but only if the target path is inside of the mapped path.

Agree. Think for my case that would have actually worked.

 

 

2 hours ago, mgutt said:

Depending to your target it's maybe better to create hardlinks to all the files that should be accessible through the container.

Great idea! Used this command to convert my symlinks into hard links and now it works perfectly! Thank you!

 

Marking this as solved.

Link to comment
  • froland80 changed the title to Convert symlinks absolute to relative paths (SOLVED)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.