How can I copy a file or a folder in the same manner as ditto, via Swift? What I mean is that all file attributes - extended attributes, permission settings, flags, timestamps, etc - are maintained on the copy?
I have tried the following:
However, in my testing, this maintains some attributes, but the extended attributes get mangled a bit. For example, I applied a quarantine flag to a test file, and here's what it looks like on the original and new files:
If I copy the file using ditto instead, I get this:
I could simply call ditto from Swift, but that's a less ideal solution.
I have tried the following:
Code Block try FileManager.default.copyItem(atPath: srcPath, toPath: destPath)
However, in my testing, this maintains some attributes, but the extended attributes get mangled a bit. For example, I applied a quarantine flag to a test file, and here's what it looks like on the original and new files:
Code Block $ xattr -l test.txt newtest.txt test.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642 newtest.txt: com.apple.quarantine: 0082;6051c84a;;
If I copy the file using ditto instead, I get this:
Code Block $ ditto test.txt newtest.txt $ xattr -l test.txt newtest.txt test.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642 newtest.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642
I could simply call ditto from Swift, but that's a less ideal solution.