[Geany] Problems when "no space left on device"

Enrico Tröger enrico.troeger at xxxxx
Fri Apr 25 13:12:17 UTC 2008


Hi,

yesterday an user reported that Geany behaves badly when there is no
free disk space on the disk where the current file should be saved.
That is, when you are editing a file in Geany, meanwhile your disk runs
out of free space (extensive logging, copying large files, some
process gone bad, ...) and you then save the file in Geany, it gets
overwritten and the file is emptied.
This is indeed bad.
And there seems to be no easy way to fix it.

The only solution which comes to my mind would be to check for
available disk space before trying to write the file. Unfortunately,
there seems to be no portable way of doing this.
There is statvfs() for Linux and some Unices but I'm not sure it is
generally available. And then there is Windows which again would need
some special code.

IMO, fopen() should fail to open a file for writing (mode "w") when
there is no free space available and it should set errno to ENOSPC.
Unfortunately, it doesn't. Instead it does open the file, returns a
valid FILE* object and truncates the file.
Then the following fwrite() call fails and sets errno to ENOSPC. But
unfortunately at this point the file already got truncated and is empty.

I tried to first open the file with the "a" flag in append mode, then
try to add some characters and if that fails, abort with an appropriate
error message. And if it succeeds, re-open the file for normal writing
and put the contents as usual.
Unfortunately, this also doesn't work reliably. So, I'm not sure if we
can/should do anything else about this.

Take this as a warning and please try to prevent the case of a full
disk.

BTW, Geany is not the only app with such problems. Xfce's mousepad and
SciTE have the same problem. And there are probably many more
applications which similar problems.

Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/users/attachments/20080425/dd5c9a98/attachment.pgp>


More information about the Users mailing list