2012-03-21 64 views
2

我正在使用copyItemAtPath:toPath:error:進行復制操作。從技術文檔:NSFileManager中的錯誤(實例方法遍歷符號鏈接)

Symbolic links are not traversed but are themselves copied

但這種方法遍歷符號鏈接和複製由ln -s創建符號鏈接的一部開拓創新的內容(10.5)。
kMDItemFSFinderFlags對於由ln -s創建的別名爲零。
attributesOfItemAtPath:error: returns NSFileType = NSFileTypeSymbolicLink

What's the difference between alias and link?

An alias contains two pieces of information: a unique identifier of the file it links to, and the path and file name of the file it links to.

If you rename or move a file, and then create a new file with the path and file name that the file originally had, then any alias that linked to the original file now links to the new file.

However, if you rename or move a file without replacing it, and then invoke an alias, the alias is updated to point to the new path and file name, making use of the unique identifier to do so.

A symbolic link, on the other hand, does not contain a unique identifier to a file, and would appear as broken if the file is renamed or moved and not replaced with a file of the same path and file name.

當我使用

tell application "Finder" 
    make new alias at POSIX file "/Users/test/" to POSIX file "/Applications/Safari.app" 
end tell 

copyItemAtPath:toPath:error:工作正常和kMDItemFSFinderFlags = 33792創建別名。

attributesOfItemAtPath:error: returns NSFileType = NSFileTypeRegular; 

任何人都可以幫我嗎?

回答

0

如果這確實是一個錯誤嘗試使用copyfile()(C函數,man部分3)來代替。

+0

如果文件是符號鏈接(4KB),則copyfile()在10.5中複製零KB。在10.6工作正常。 – 2012-03-22 08:17:53

+0

copyfile((const char *)[srcpath UTF8String],(const char *)[destpath UTF8String],state,COPYFILE_DATA | COPYFILE_XATTR | COPYFILE_STAT | COPYFILE_ACL | COPYFILE_NOFOLLOW_SRC); – 2012-03-22 08:18:51

+0

在10.7中也複製0KB – 2012-03-22 08:29:30