opam
opam copied to clipboard
opam behavior when disk is full
On 2.0, when doing opam switch remove foo while disk is full:
- opam fails with an exception
- the switch is not removed
~/.opam/configis replaced by an empty file
I understand that handling a full disk is complicated, but I would like if it at least didn't made my opam install unusable. :(
Sorry about it! Are there standard solutions for handling this ? The one I can imagine is to always write to temp files, then swap. We would have to update how we lock the files (to prevent concurrent read/writes) since at the moment it's done on the file's inode.
On second thought, just removing the file in the handler of exceptions that are raised during write should already help a lot, shouldn't it ?
Might having a small permanent file created by opam init help in some cases - i.e. a small reservation of disk space? Obviously doesn't help if you have another active process which is chomping any disk space remaining, but it might be enough to ensure that config files are written back?
I just ran into this problem. I think doing atomic writes of files (writing, fsyncing, then swapping the files) would make sense and avoid a lot of problems with low disk space.
Problem encountered with an upgrade & repo config file in #4157
Note that there's a commit already for atomic writes in https://github.com/ocaml/opam/commit/bb0d675dba3c6c128470d7fc41160837bf757a78 (in https://github.com/ocaml/opam/pull/5417) - that could possibly be extracted early?
On opam 2.1.2 I somehow managed to hit an even weirder instance of this issue. After running out of disk space during switch creation, ~/.opam/config was not just replaced by an empty file, but this abomination: opam-config-vpl-k.txt.
It appears to have some kind of terminal output with escapes prepended to the usual config file??? I don't really understand how that can even happen. Some file descriptor mixup?
@pitag-ha also hit the same issue last week with also some sort of corruption of the file description. We have no idea what's happening there.
The file corruption issue should be fixed by https://github.com/ocaml/opam/pull/5489 in opam 2.3, however the more general issue of having partial states kept around is more complicated to fix so i'm keeping this issue open for it.