I re-wrote lrucache (and it seems like no-one had looked at it much
before :). I was told my test function would have been simpler in
native py.test, so let's have a go converting it all.
We can avoid any reference to unittest, because lrucache doesn't write
files so it doesn't need any of our custom assertion helpers.
dict.pop() will raise KeyError for us if necessary. I was confused
because we used to have lrucache.pop() with a bug, that returned None
instead.
Great catch by @ThomasWaldmann.
At least one programmer is confused by my abuse of KeyError()
as a sentinel value. Let's call the sentinel value _NotFound
instead, and let's avoid re-creating it on each call.
I have a new favourite line of code, "if item is _NotFound" :).
Thanks to @ThomasWaldmann for all these review suggestions.
We need to make sure dispose() is always called when necessary.
Using inheritance it's just too easy to forget a method,
that we needed to override.
I also find it confusing when an override method calls another
method, and you have yet to see whether the latter method is
overridden or not. It didn't help that most of these methods
are actually operator overloads.
This turns out to require _less_ code :-).
(Admittedly the code could have been reduced a bit anyway
because python3's super() can be called without any arguments).
The initializer now takes a dispose function. lrucache
claims ownership of the items it contains and will dispose
deleted items. Ownership can naturally be reclaimed by calling
pop() for the item.
Suggested by @ThomasWaldmann. Avoiding a complex assumption
should make the code easier to understand and maintain.
(Technically we do have an fd for the segment, because
the only caller opens the segment and checks it before
calling for repair.)
found out why it could not install llfuse into virtual env: it always complained about
not being able to find fuse.pc - which is part of libfuse-dev / fuse-devel and was missing.
once one adds the fuse dev stuff, llfuse installs to virtual env without problems.
When we delete a segment, let's close its fd as well.
Note as well wasting the fd, this was forcing the
filesystem to preserve the deleted file until we exited.
I noticed roughly 20 open fds of deleted files when
attic saved 10G of data.
this was left over from times when we either used mock from stdlib
or pypi mock. but as we only use pypi mock now, the indirection is
not needed any more.
if one used --last (or since shortly: gave an archive name), verify_chunks (old method name) was
not called because it requires all archives having been checked.
the problem was that also the final manifest.write() and repository.commit() was done in that method,
so all other repair work did not get committed in that case.
I moved these calls that to a separate finish() method.