Sample Header Ad - 728x90

Can Linux files systems resolve a relative path before resolving symlink?

4 votes
1 answer
142 views
New Linux user here, freshly transitioned from Windows 10 to Fedora 41. Lot's of experience with many OS's, including various *nix and Unix-like file systems. I have a standard practice of using symlinks from test folders to code repos in order to recreate the deployed production folder structure locally for testing, while keeping testing and the code repo cleanly separated. I have many projects set up like this for local testing. This looks as follows, for example:
`
~/dev
  test
    a-project
      app => ../../code/a-project/src
        (cfg)
        (web)
      dta
        cfg
  code
    a-project
      src
        cfg
        web
` Key to this problem is that the src/cfg folder (which in production is the app/cfg folder) holds files that have relative references to optional files in dta/cfg which are loaded if they exist in production, expected to be relative to the app/cfg folder. Thus ../../dta/cfg/Optional.json when deployed references the dta folder. The PWD is the application root (in testing, this is ~/dev/test/a-project and all paths in the software are specified relative to the PWD. These paths are manipulated in Java code, using Java's File class, so this is not a shell-behavior problem. This works perfectly well in Windows, since the filesystem takes the path app/cfg/../../dta/cfg/Optional.json to mean exactly what it looks like, and resolves the relative references first, resulting in dta/cfg/Optional.json (the leading app/cfg being eliminated by the following ../... But Linux apparently resolves the symlink *first* (app/cfg/ => dev/code/project/src/) and only then then applies the relative path segments ../../dta/cfg/Optional.json, resulting in a file not found because, of course, the file is *not* located in ~/dev/code/project/dta/cfg. Regardless of arguments about whether this is technically correct or not, is there any way that I can tell Linux at any level to resolve relative path segments before resolving symlinks so that this unexpected and unpredictable behavior does not occur? Apart from being confusing and counter-intuitive to me, I have a lot of existing code which expects paths to resolve relative references first, that is using the apparent path, not the underlying path. The file system for my dev work is ext4 with case folding enabled (having come from Windows, and needing to remain compatible with other devs using Mac and Windows), and I'd really, *really* like to avoid making a destabilizing, invasive change to a bunch of Java classes to implement the relative path resolution before passing the path to the OS; both because it's potentially brittle, leading to security flaws, and because it's only needed for my testing as production systems (Ubuntu Linux servers) do not need these symlinks.
Asked by Cornelius Dol (143 rep)
Jan 15, 2025, 01:53 AM
Last activity: Jan 16, 2025, 09:01 AM