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

Use the -f flag instead of -m flag for readlink #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Guiorgy
Copy link
Contributor

@Guiorgy Guiorgy commented Nov 25, 2024

The -m flag isn't as portable as I thought. According to Mark Altmann, the -m is not available on older Mac systems, and may not be available on BSD.

The -f flag should be more universal.

I'll test to make sure all things work as they did, until then I'll leave this as a draft.

Edit: Here's a list of things I tested:

  • Normal paths (not containing any links) work as before, so no issues here.
  • If the destination path (e.g. test4/mosquitto_config.tar.gz) contains a link to itself (e.g. test4 -> test4), readlink with -m returns the path to the link (e.g. /home/user/directory/test4), while with -f it returns an empty string. Either case results in a Docker error, though different ones.
  • Paths containing 1 valid link work as intended (e.g. 'test5 -> test3', test5/mosquitto_config.tar.gz, both -m and -f correctly resolve to /home/user/directory/test3)
  • Using paths with last link pointing to a nonexistent directory works in both cases (e.g. running rm -rf test3 in the above case before exporting), though this will create that missing directory
  • Paths with multiple links work the same in both cases (e.g. test6 -> test6.1 and test6.1 -> test3 when destination is test6/bitwarden_data.tar.gz)
  • If the destination contains a link to a nonexistent directory and the target is a subdirectory, -m works but -ffails (e.g.test7 -> test3and destination istest3/test/mosquitto_config.tar.gz, but test3 doesnt exist (rm -rf test3), then -mreturns the correct path/home/user/directory/test3/test, but -f` return an empty string)

Overall, the main difference, from what I can tell, is that -f will faill if a link in the middle of the destination path points to an invalid object, wheres -m works, which was the reason of using it in the first place:

-m, --canonicalize-missing
canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence

If we use -f, might be worth erroring out with a better message when readlink returns an empty string. I'll add that if you agree with that.

The -m flag isn't as portable as thought. The -f flag should be more universal.
@Guiorgy Guiorgy marked this pull request as ready for review December 4, 2024 13:24
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

Successfully merging this pull request may close these issues.

1 participant