bug in file.write() ?

Bengt Richter bokr at oz.net
Sat Aug 2 09:35:40 CEST 2003


On Sat, 02 Aug 2003 07:08:20 GMT, sjmachin at lexicon.net (John Machin) wrote:

>On 31 Jul 2003 15:43:34 -0700, pu at vo.lu (Patrick Useldinger) wrote:
>
>>Hi,
>>
>>I think I found a bug in the write method of file objects. It seems as
>>if before writing each block, a check was done in order to verifiy
>>that there is enough space left for the *whole* file, not for the
>>*remaining* data to be written.
>
>This is very unlikely --- it is difficult to determine reliably the
>available space on a disk or tape volume; if one were really
>interested, one would do it once before trying to write the file, not
>before writing each block. No, the expected implementation, which you
>can check against reality by inspecting the source (fileobject.c), is
>just to attempt to write, and throw an informative-as-possible
>exception if the write fails.
>
>Despite the appearance that you have about 6KB margin of safety,  you
>will probably find that you don't have any --- the quoted size of the
>source file doesn't include the unused space in the last cluster or
>block or whatever. It's a while since I've had to concern myself with
>this sort of detail, but it's a good bet that the "chunk" size on your
>disk is 8Kb or more and you're out of luck.
>
Besides chunks of data, directories and allocation info also take up nonzero
space, and unless you have a file system with a fixed reserve for that stuff
(maybe some unusual custom floppy format?) it's going to take its byte out
of the total. How much will depend on how that nondata stuff is implemented.
A thick tree of directories max deep and all single-cluster data files will
surely be different from a single large file.

>>
>>It happens both under 2.3 and 2.2.3.
>>Any ideas? 
>
>[snip]
>
>>  File "C:\Python23\lib\shutil.py", line 39, in copyfile
>>    copyfileobj(fsrc, fdst)
>>  File "C:\Python23\lib\shutil.py", line 24, in copyfileobj
>>    fdst.write(buf)
>>IOError: [Errno 28] No space left on device
>>
>>I:\My Programs\dfc>dir f:
>> Volume in drive F is Backup 01
>> Volume Serial Number is E2CB-1650
>>
>> Directory of F:\
>>
>>18/05/2002  15:39       <DIR>          .
>>18/05/2002  15:39       <DIR>          ..
>>01/08/2003  00:25          299.630.592 dfcArchive cheetah
>>20030731-234648 F.zip
>>               1 File(s)    299.630.592 bytes
>>               2 Dir(s)     299.636.736 bytes free
>>
>[snip]

Regards,
Bengt Richter




More information about the Python-list mailing list