Write metadata, take two...

This is an updated version of my previous pull request, #1517.

It's slightly improved in that it now can use the `setfattr` commandline utility if the `xattr` module isn't installed.