Late yesterday, I was watching files being duplicated by my copyFile handler that uses ...
do shell script "cp -np " & sourcePath & space & targetPath
when I noticed that the file's label was being preserved. That's what the -p is for. The file's metadata contains the parameter kMDItemFSLabel whose value determines the file's color label. This value is preserved in the copy and the Finder displays its correct color. I don't have to read/restore the label before/after using the copyFile handler.
This prompts the question: "Why do I have to read/restore the value of kMDItemFinderComment ?"
If a file has a comment, then kMDItemFinderComment exists with the correct value, it IS preserved in the copy and the Finder should simply display it without having to read/restore.
I have also noticed that while a file without a comment should have
kMDItemFinderComment = ""
in the metadata, it actually has metadata that lacks the kMDItemFinderComment parameter. This parameter only appears when you write a comment (set comment of fileAlias to ...).
The files I am copying DO have a comment, but why is the Finder not displaying it unless I read/restore the comment? I smell a bug here.