ned14 / llfio

P1031 low level file i/o and filesystem library for the C++ standard
https://ned14.github.io/llfio/
Other
880 stars 45 forks source link

Suggestion for mapped relink() fallback on windows #132

Open patstew opened 5 months ago

patstew commented 5 months ago

Currently the docs for mapped_file_handle say:

You are guaranteed on Windows only that `address()` will not return a new value unless:
...
4. You call `relink()`, which requires closing and reopening the map because you cannot
rename a file with an open map on Windows.

which is true, but what you can do is link+unlink it which has almost the same effect, except you can't reuse the old filename until you release the handle. Might be a useful fallback for mapped_file_handle::relink and/or relink_or_clone_copy_unlink? It's useful, at least to me, to be able to rename a mapped file without changing address or having to copy the whole thing.

ned14 commented 5 months ago

To be clear, you're suggesting that instead of renaming the file with an open map, you just keep adding hard links until when you eventually tear down the map and close the file, all the links now marked delete on close will get cleaned up?

patstew commented 5 months ago

Yes, basically. Though I was only thinking about doing it once. I haven't thought through all the implications, In my case I create a temporary file which the user can choose to save later on, and with this workaround I can avoid waiting for all my threads to stop looking at the map so I can relink it, or having to copy it, for the sake of windows.