drl37530 2013-05-14 16:37
浏览 126
已采纳

复制包含符号链接的继承目录

This is similar to questions that have been asked before, but I promise it is different.

I have a site that involves inheritance from a parent to a child site. Part of this is media. To make media serve faster, I am creating a symlink-ed copy of the parent directory in the child, then override those with any files the child specifically defines. This allows apache to serve statically from the media (which may come from a parent) while inheriting html form the parent.

Example after build where inheritance is 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)

So I could symlink to /images/muffins.png and receive the correct media based on the site that I'm on. The site-specific media is stored in the same directory structure, but in a different location only containing media specific to that site.

The issue is that no matter how I try to do it, the second child ends up with a symlink to its parent, not the originator. In the example above, I cannot get /some/direcory/cars/images/cats.png to point to the common media programatically, only the maps media.

Currently I am using the command cp -sR /some/directory/maps/* /some/directory/cars/

I'm running this on PHP, but currently using cp and ln commands in the PHP exec() function to build these structures.

  • 写回答

2条回答 默认 最新

  • duanfei1930 2013-05-14 17:08
    关注

    It seems you should use tar and not cp : please try (I can't test it right now; watch out what your versino of tar does by default with symlinks. it should save them as symlinks, not follow them... but 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程