gpt4 book ai didi

objective-c - NSFileManager 中的错误(实例方法正在遍历符号链接(symbolic link))

转载 作者:行者123 更新时间:2023-12-03 16:43:33 25 4
gpt4 key购买 nike

我正在使用 copyItemAtPath:toPath:error: 进行复制操作。来自文档:

Symbolic links are not traversed but are themselves copied

但此方法正在遍历符号链接(symbolic link)并复制 ln -s 创建的符号链接(symbolic link)的原始内容(10.5 中)。
对于 ln -s 创建的别名,kMDItemFSFinderFlags 为零。
attributesOfItemAtPath:错误:返回 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; 

谁能帮帮我吗?

最佳答案

如果这确实是一个错误,请尝试使用 copyfile() (C 函数,man 第 3 节)。

关于objective-c - NSFileManager 中的错误(实例方法正在遍历符号链接(symbolic link)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9804722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com