Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 9 '11 at 22:58

This question came from our site for professional and enthusiast programmers.

    
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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
share|improve this answer
    
Maybe call it something like rootdir rather than source. –  tripleee Sep 9 '11 at 7:04
    
As i previously noted, the path software use as root is dynamic, so symlinking it will be hard. –  Eye of Hell Sep 9 '11 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. –  sanmai Sep 10 '11 at 1:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.