2013-05-14 50 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