2013-05-14 124 views
0

这与先前提出的问题类似,但我保证它不同。复制包含符号链接的继承目录

我有一个网站涉及继承从父母到子网站。其中一部分是媒体。为了使媒体更快地服务,我创建了子目录中父目录的符号链接副本,然后用孩子特别定义的任何文件覆盖这些副本。这允许apache从媒体(可能来自父代)静态提供服务,同时从父代继承html。构建完成后

例子继承共> maps->汽车:

/some/directory/common/ 
    images/ 
     cats.png 
     muffins.png 
    css/ 
     styles.css 

/some/directory/maps/ 
    images/ 
     cats.png -> /some/directory/common/images/cats.png 
     muffins.png (overridden by child) 
    css/ 
     styles.css -> /some/directory/common/css/styles.css 
     mapsStyles.css (child only) 

/some/directory/cars/ 
    images/ 
     cats.png -> /some/directory/common/images/cats.png 
     muffins.png -> /some/directory/maps/images/muffins.png 
    css/ 
     styles.css -> /some/directory/common/css/styles.css 
     carsStyles.css (child only) 

所以,我可以根据我是在网站上的符号链接到/images/muffins.png和接收正确的介质。特定于站点的媒体存储在相同的目录结构中,但存储在只包含特定于该站点的媒体的其他位置。

问题是,无论我如何尝试这样做,第二个孩子的符号链接最终都会与其父,而不是始发者。在上面的例子中,我无法获得/some/direcory/cars/images/cats.png以编程方式指向常见媒体,只能看到地图媒体。

目前我使用的命令cp -sR /some/directory/maps/* /some/directory/cars/

我上运行PHP这一点,但目前使用的PHP exec()功能cpln命令来建立这些结构。

+0

只是浏览questino实际上不花时间神交它:这听起来像一个时间使用'tar'(约符号链接正确的选项,根据需要)而不是“cp”... – 2013-05-14 16:55:09

+0

所以你想要使符号链接到父级,除非父级已经包含符号链接,那么它应该是符号链接t原来的? – Barmar 2013-05-14 17:10:04

+0

正确,Barmar。否则,我会得到太多级别的符号链接。 – Boerema 2013-05-14 17:14:50

回答

1

看来你应该使用tar而不是cp: 请尝试(我现在不能测试,看什么 versino焦油确实在默认情况下符号链接,应该将其保存为符号链接,不跟着他们......但情况因人而异):

#step 1: create an archive of one of the directories_using_common_symlinks: 
cd /some/directory/maps/ 
tar cvf /somewhere/wholeshebang.tar images/ css/ 
     #ie, tar everything (directories, symlinks, etc). 
     #Please add whatever is missing 
     #note: it will also contain extra (specific) stuff, which we get rid of below 

#step 2: create the real archive of JUST the common stuff 
cd /some/temporary_dir/ 
tar xvf /somewhere/wholeshebang.tar #regurgitate all the content. 
rm  /somewhere/wholeshebang.tar #we won't need that one anymore, it contains too much 
rm images/muffins.png css/mapStyles.css #delete all extra stuff 
tar cvf /somewhere/just_commons.tar #recreate tar, this time with only common stuff. 

#step 3: use the new archive to "kickstart" the other directories 
cd /the/destination 
tar xvf /somewhere/just_commons.tar #regurgitte the common stuff (dirs, symlinks) 
#then add whatever is specific to /the/destination 
+0

我正在检查这个......但它看起来很有希望。我会尽快给您回复。 – Boerema 2013-05-14 17:13:47

+0

@boerema:我可能还没有真正回答过你的“父母/孩子”部分,但我希望我理解下面的需要^^,即只需tar其中一个最常用东西的链接(或创建一个,每一个链接都是通用的东西),清理它只包含常见的东西,然后用它来“启动”新的孩子......然后根据需要用特定链接替换常用链接(并添加所需的任何内容)。 – 2013-05-14 17:16:46

+0

正是如此。我在想你的解决方案将父目录解压缩到第一个子目录中,这样可以保留原来的符号链接,解决我的问题。 – Boerema 2013-05-14 17:30:40

0

如果问题仅仅是链接.....你可以尝试 “CP -l” ......(检查人的CP获取更多信息)

手册页:

-l, --link 
    hard link files instead of copying 

因此应该解决这个问题!

+0

-s标志执行此操作,它只是不会创建与原始目标相同的目标符号链接。它创建链接到复制的符号链接。这是我的理解,-l将建立一个硬链接,而不是符号链接。 – Boerema 2013-05-14 16:51:48

+0

-s标志用于符号链接,-l标志用于硬链接 man info :: -s,--symbolic-link 使符号链接代替复制 – nsd 2013-05-14 16:53:25

+0

我相信我在问题中说我正在制作符号链接,而不是硬链接。 – Boerema 2013-05-14 16:54:48