Fixing files marked as stuck as partially transferred in Finder

Very rough note, but if I don’t write it down, no one else will find it. A friend was dealing with an issue where she interrupted a file transfer of many files and directories to an SMB share on macOS and transferred it via other means. However, macOS thought the files were still in a partially transferred state to be resumed. There was no obvious way to tell Finder that it was OK.

It seems that clearing a file’s extended attributes can clear this out. A quick way to remove all extended attributes from everything in the current directory:

shopt -s globstar
xattr -c **

Be careful with this – you might have files that do need the extended attributes. In this case, it wasn’t needed. Read on for the theory on why this might work and the specific attribute that might be a problem.

Continue reading

Dealing with key-based polymorphic JSON in Swift Codables

I’ve been trying to use Swift’s Codable protocol with some data I wanted to decode over the wire. Codable makes it easy to serialize things in Swift. Unfortunately, the schema of the protocol I was using doesn’t cleanly map to something easily represented in Swift. It consists of a single object, with a single key, and the key’s name determining its value and type. For example, various JSON blobs:

{"Chat": {"message": "Hello world!"}}
{"Error": {"message": "Invalid request"}}
{"Hello": {"username": "alice", "version": "1.0"}}
/* there are more, but we'll stick with this set for the example */

How do we decode this cleanly?

Continue reading