|
Posted by Gordon Burditt on 05/18/06 22:08
>> There was some disk space issues with my server. As a result any script
>> I had that opened a file for writing would clobber it i.e uncate it to
>> zero length . Since there was no space left on device, nothing would be
>> written to it.
>>
>> Are there any workarounds to this?
Buy a bigger disk?
>> Does opening the r+ or w+ make a
>> difference instead of just w ?
>w and w+ can be dangerous if you have disk space issues because they
>truncate the file on open, without a check if you can write data to
>the file again.
If you're going to truncate the file, that's by itself dangerous
whether or not you can write data to the file.
>So i suggest open with r+ and do a is_writable() (i
>think it will return false if no disk space is avail) just before you
is_writable() should NOT return false if no disk space is available,
since you can still write to the existing portion of the file,
and just because there is disk space when you do is_writable() doesn't
mean there's disk space available when you write.
>attempt to write, if it fails, close the file and no data is lost, if
>it returns true you can ftruncate() the file to start from 0.
>But there can still be issues, like if you dont have enough space to write
>the entire content etc...
I recommend writing a new file (in the same directory as the old one),
and when you've finished it, rename it into place under its proper name.
Gordon L. Burditt
Navigation:
[Reply to this message]
|