[Geany-devel] Changed file saving implementation for systems with GIO
lists.ban at xxxxx
Thu Nov 4 22:37:28 UTC 2010
Le 04/11/2010 21:42, Dimitar Zhekov a écrit :
> On Thu, 4 Nov 2010 17:53:47 +0000
> Nick Treleaven <nick.treleaven at btinternet.com> wrote:
>> So it seems that function doesn't handle disk exhaustion safely. (But
>> this is no worse than before for Geany).
> Before we had safe or unsafe file saving. Let's keep that choice, shall
> we? I can write the patch, it's only a few lines.
> For more than 20 years now, the only safe save is to write the data
> into a temporary file in the same directory, and then rename it over
> the target file. Even if the rename fails, you still have the temporary
> file. That changes the onwership and permissions, which is exactly the
> behaviour of the safe g_file_set_contents().
Well... stop me if I'm saying bullshit but what about:
backup = path + '~' # or whatever
if copy (path, backup_path): # COPY file to the backup
if not write (path, data): # write in original file
move (backup_path, path) # if write failed, restore backup
elif not make_backup:
unlink (backup_path) # if no backup is to be done, delete backup
The problems I see are:
1) needs at least 2 times the size of the file in the target directory
(but it's the same anytime we bake backups)
2) backup file may have altered permissions/attrs
3) ...so if write fails, we have changed the permissions/attrs on the
In the worst case, the original file has another name and lost its
The advantages I see are:
1) the permissions/attrs are kept on success, as well as hard links
2) no data can be lost (if the FS is reliable)
The key idea is not to move the original file but to copy it. So we can
safely overwrite the original (and the keep permissions/attrs), once the
backup is done.
>> Perhaps you might like to file a bug against GIO. Perhaps first use gdb
>> to break on that function just to be absolutely sure.
> Perhaps. But bugs filed to gnome and kde may take years to resolve...
...but if nobody files them, they are likely to never be fixed.
More information about the Devel