0

这与之前提出的问题相似,但我保证会有所不同。

我有一个涉及从父站点继承到子站点的站点。其中一部分是媒体。为了使媒体服务更快,我在子目录中创建了父目录的符号链接副本,然后使用子目录专门定义的任何文件覆盖这些副本。这允许 apache 从媒体(可能来自父级)静态服务,同时从父级继承 html。

构建后的示例,继承是 common->maps->cars :

/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 函数中使用cpln命令exec()来构建这些结构。

4

2 回答 2

1

看来你应该使用tar而不是cp:请尝试(我现在无法测试它;注意的 tar 版本默认使用符号链接做什么。它应该将它们保存为符号链接,而不是跟随它们......但是 ymmv):

#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
于 2013-05-14T17:08:52.743 回答
0

如果问题只是链接......你可以尝试“cp -l”......(查看 man cp 了解更多信息)

手册页:

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

因此应该解决这个问题!

于 2013-05-14T16:44:04.107 回答