I have a third-part software with external configuration that takes "path to file" as input parameter. Unfortunately, this software concatenates path given with some predefined path. For example, it expects 'data/images' as parameter and will use '/Users/someuser/work/source/data/images'. I want to specify and absolute path, but giving something like '/tmp/images' to this software will just result in unexisting path '/Users/someuser/work/source//tmp/images' being used :(. Is it some path trick i can use alongside of '..' so i can give software something
that will result in absolute path after software concatenates it with predefined one. Using '..' works but it's not a very good solution since path configuration is static and predefined path software use can change.
-
stackoverflow.com/questions/2564634/…– Vivek GoelSep 9, 2011 at 6:24
2 Answers
There are myriads of possibilities to make /Users/someuser/work/source/XXX
to point wherever you want to in Linux:
Use symlinks - doing something like:
ln -s /wherever/you/want /Users/someuser/work/source/XXX
would make
/Users/someuser/work/source/XXX
to appear as a directory. If some software would travel there and/or write files there, they would end up in/wherever/you/want
.Mount some other filesystem in
XXX
, i.e.mount /dev/something /Users/someuser/work/source/XXX
This way you'll get your /dev/something device mounted right at the directory the application would write to.
Do a "bind mount", i.e. rebind a part of some other filesystem (already mounted) to
XXX
:mount -o bind /wherever/you/want /Users/someuser/work/source/XXX
It works much like a symlink, but it's much harder to detect by application. Application might easily check whether target directory is a symlink and refuse writing there, while bind mount method provides a normal directory, but it's contents would
Use a unionfs-like filesystem, such as unionfs or aufs - this way you can "unify", i.e. mount simultaneously several filesystems in one directory (i.e.
XXX
)Play some tricks with LD_PRELOAD and libraries that override methods, such as
open()
,fopen()
, etc - the most prominent one is fuse, namely, you might want to check out Union-like filesystems for FUSE.
If you symlink /Users/someuser/work/source/
to /
(root)
work$ ln -s / source
Every path there will be based off the root:
/Users/someuser/work/source/tmp/images
will point to
/tmp/images
which you can check by
work$ ls source/tmp/images
-
-
As i previously noted, the path software use as root is dynamic, so symlinking it will be hard. Sep 9, 2011 at 18:49
-
As you may read from my answer, if we symlink to the FS root, nothing is ever hard. Please read my answer once again.
mount --bind
based solutions are not as near as flexible as mine.– sanmaiSep 10, 2011 at 1:26