简体   繁体   English

NSFileManager中的错误(实例方法正在遍历符号链接)

[英]Bug in NSFileManager (instance method is traversing symbolic link)

I am using copyItemAtPath:toPath:error: for copy operation. 我正在使用copyItemAtPath:toPath:error:进行复制操作。 From documentation: 从文档:

Symbolic links are not traversed but are themselves copied 不会遍历符号链接,但它们本身会被复制

but this method is traversing symbolic link and copying orignal content for Symbolic links created by ln -s (in 10.5). 但是此方法遍历符号链接并为ln -s创建的符号链接复制原始内容(在10.5中)。
kMDItemFSFinderFlags is zero for alias created by ln -s . 对于ln -s创建的别名, kMDItemFSFinderFlags为零。
attributesOfItemAtPath:error: returns NSFileType = NSFileTypeSymbolicLink

From What's the difference between alias and link? From 别名和链接有什么区别?

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. 另一方面,符号链接不包含文件的唯一标识符,并且如果文件被重命名或移动并且未替换为具有相同路径和文件名的文件,则符号链接将显示为损坏。

when i am creating alias using 当我使用创建别名时

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

copyItemAtPath:toPath:error: is working fine and kMDItemFSFinderFlags = 33792 . copyItemAtPath:toPath:error:运行正常, kMDItemFSFinderFlags = 33792

attributesOfItemAtPath:error: returns NSFileType = NSFileTypeRegular; 

Can anyone please help me out? 有人可以帮我吗?

如果确实存在错误,请尝试使用copyfile() (C函数,手册第3节)代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM