How to rewrite files in Linux
bugs.edge.launchpad.net
How to rewrite files in Linux
1–10 of 22 posts
Re: How to rewrite files in Linux
#2Even more approaches to rewriting: http://bitworking.org/news/390/text-editor-saving-routines
Re: How to rewrite files in Linux
#3Re: How to rewrite files in Linux
#4For approach #2, can you lose the file completely or only the new version? In many cases it would be acceptable if the old version was still there after a crash (ACI semantics).
I suspect this could be solved fs-side using a journal that doesn't just store metadata (as most do) but also file content. Slow, though, as files are effectively written to disk twice.
Re: How to rewrite files in Linux
#5For approach #2, can you lose the file completely or only the new version? In many cases it would be acceptable if the old version was still there after a crash (ACI semantics).
But even if it doesn't the write and the rename are not correlated so it's still not safe. e.g. the move does not occur iff the write completes.
Is there any way to queue the move as a system call?
Re: How to rewrite files in Linux
#6Re: How to rewrite files in Linux
#7Applies to other programming problems as well, I think I'll use this when I next time see someone "optimizing" SQL database transactions.
Re: How to rewrite files in Linux
#8For Gnome and KDE, Ted suggests using BDB or an idealized version of SQLite instead of the current dot-directories, but I don't imagine that change being implemented any time soon -- Firefox still has some lingering problems from that transition.
Re: How to rewrite files in Linux
#9This is also risky because it could leave the file in an inconsistent, partially-modified state. However, in practice it seems to work really well, and Google turns up a striking lack of articles discussing the risks of inconsistency due to use of mmap.
I'd like to learn more about the risks of this approach, since I'm using it to selectively rewrite portions of a very important file in a project of mine. I'm pretty sure that my usage pattern is safe. The writes are small enough that they nearly always affect only one disk block and never touch more than two, and I'm careful to msync() at the right places (actually mmap.mmap.flush(), since I'm using Python), but I'm interested in learning about potential issues. This file is too large to make copying it convenient, but I'll do that if necessary.
Re: How to rewrite files in Linux
#10Pseudo related: I wish I could have anonymous temporary files and associate them with a name later. Temporary name handling is just bugs waiting to happen. Even if you do it securely, how many programmers have a way of cleaning up spurious debris that might be left after an inelegant termination?