Lykso's Union File System, or lufs, is a fork of the "newunionfs" example from go-fuse. It is a simple implementation of a union filesystem in userspace via FUSE. Files in lower layers are guaranteed to remain in those layers when edited or moved around. New files get created in the topmost layer. Files can be moved between layers at will without causing problems. There is no balancing of files between layers, and there is no "copy-on-write" option. New files are created in the top layer.
Deleting files and directories
Deleting regular files only deletes them from the topmost layer containing each file, leaving any same-named files in the layers beneath alone.
Deleting directories deletes them from each layer they appear in, starting from the topmost layer, until either the directory has been removed from all layers or the directory removal from a layer fails.
Directories are treated differently because leaving behind a bunch of empty
directories across each layer after an
rm -rf seemed like it would get
annoying quickly. In my use case, files will rarely shadow each other, but
directories will almost always have shadows in other layers.
Unlink and create versus directly writing
Some programs, such as vim, will, when saving, unlink the original file and create a new file containing the edited contents. To detect this and keep the newly created file in the same layer as the original file whose place it's taking, a record of recently deleted files is kept and any file created at the same path within one second of that path having been unlinked will be written to the layer the deleted file belonged to.
Use as a library
LUFS can also be used as a library to mount a union filesystem from within a program. When used this way, layers can be appended to the bottom of the stack after mounting. LUFS should also be concurrency-safe, though this has not been rigorously tested, much like the rest of this project's codebase at time of writing.