Implemented two ways to fix #46:

* Write locks: when a file is being written it sets a lock that other
* operations have to wait for
* Writing to a temporary file first, then copying that to the
* destination file (copying permissions as well). THis avoids truncation
* in case of a crash or broken connection.