I've been browsing for a minute now trying to find a way to create a relative symlink inside a relative symlink, and what I mean by that is this...

I have my CakePHP Templates Skeleton as a symlink inside one of my projects, inside my skeleton, I have a symlink to a plugin outside the skeleton folder, the idea being, I can symlink my CakePHP CMS Skeleton inside my projects, create an "Application" plugin outside the CMS skeleton symlink, and and the skeleton symlink point to my projects "Application" plugin.

By that I mean the following.

I have a CakePHP CMS Skeleton at the following path

/mnt/proj/libs/cakephp/lib/Cake/Console/Templates/skel

The path to my project folder is below

/mnt/proj/mysite.com/

I then symlink the CakePHP CMS Skeleton inside my project folder like so

/mnt/proj/mysite.com/cms-skel -> /mnt/proj/libs/cakephp/lib/Cake/Console/Templates/skel

Inside the skeleton I have a symlink pointing to an Application plugin

/mnt/proj/libs/cakephp/lib/Cake/Console/Templates/skel/Plugin/Application -> ../../Application

So inside the CakePHP CMS symlinked folder in mysite.com folder I have

/mnt/proj/mysite.com/cms-skel/Plugin/Application -> ../../Application

The issue is, that the above symlink points to

/mnt/proj/libs/cakephp/lib/Cake/Console/Templates/Application

And I need it to point to

/mnt/proj/mysite.com/cms-skel/Plugin/Application

Any ideas on how I can do the above with symlinks is greatly appreciate, I am not even sure what to google at this point.

up vote 2 down vote accepted

You issue is you're attempting to use a single relative link that will work within 2 directory trees, and yet the relativity of the link is not the same in these 2 trees.

Example

I've created your directory structures starting at proj, but otherwise they're identical.

$ pwd
/home/saml/proj

Here's the lib/ tree:

$ tree -lf libs/
libs
`-- libs/cakephp
    `-- libs/cakephp/lib
        `-- libs/cakephp/lib/Cake
            `-- libs/cakephp/lib/Cake/Console
                `-- libs/cakephp/lib/Cake/Console/Templates
                    |-- libs/cakephp/lib/Cake/Console/Templates/Application
                    `-- libs/cakephp/lib/Cake/Console/Templates/skel
                        `-- libs/cakephp/lib/Cake/Console/Templates/skel/Plugin
                            `-- libs/cakephp/lib/Cake/Console/Templates/skel/Plugin/Application -> ../../Application  [recursive, not followed]

Here's the mysite.com/ tree:

$ tree -lf mysite.com/
mysite.com
`-- mysite.com/cms-skel -> /home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/skel/
    `-- /home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/skel//Plugin
        `-- /home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/skel//Plugin/Application -> ../../Application

So if we were to look at the Application link in the 1st tree, lib/:

$ pwd
/home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/skel/Plugin

$ readlink -f Application
/home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/Application

However, if we do the same analysis in the mysite.com/ directory we see our problem.

$ pwd
/home/saml/proj/mysite.com/cms-skel/Plugin

$ readlink -f Application
/home/saml/proj/libs/cakephp/lib/Cake/Console/Templates/Application

What's going on?

Well when you're in the mysite.com/ tree 2 levels above mysite.com/cms-skel/Plugin/ is libs/cakephp/lib/Cake/Console/Templates.

This should help to see it:

$ pwd
/home/saml/proj/mysite.com/cms-skel/Plugin

$ readlink -f ../../
/home/saml/proj/libs/cakephp/lib/Cake/Console/Templates

I do not see a way around this given the differences in the number of directories within the 2 trees.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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