Skip Menu |
 

This queue is for tickets about the File-Overwrite CPAN distribution.

Report information
The Basics
Id: 50067
Status: resolved
Priority: 0/
Queue: File-Overwrite

People
Owner: Nobody in particular
Requestors: dmuey [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: Shouldn't croak, it should retun;
Download (untitled) / with headers
text/plain 1.1k
Hello, neat module! A few things I noticed that make it impractical to use currently: 0) It should maybe not use the bare word file handle to avoid collisions, it could use a lexical var as the handle (not too big a deal since it is package specific) 1) It should not croak/die it should return; and allow the caller to handle failure. 2) print FILE $with x $bytes; is bad: a) it assumes $with is one byte (which it is unless they call the internal function, so not too big of a deal) b) it uses $bytes amount of memory to create the junk data since '$with x $bytes' creates the string in memory before passing it to the handle (ie.e try to overwrite a 1 GB file == 1 GB of memory used by the script) A while() or for() with numbered .. range is much more memory efficient: for (1 .. $bytes) { print {$fh} $single_byte; } You could do fewer iterations with larger chunks but that is currently neither here nor there :) 3) close() is not checked for success (try this as a user who is over their quota. every thing will work fine until close() fails with over quota errno) 4) in overwrite_and_unlink() you shouldn't do the unlink unless the overwrite returned successfully HTH :)
Subject: Bugs/misfeatures in File::Overwrite
Download (untitled) / with headers
text/plain 1002b
Show quoted text
> 0) It should maybe not use the bare word file handle to avoid > collisions, it could use a lexical var as the handle (not too big > a deal since it is package specific)
Fixed Show quoted text
> 1) It should not croak/die it should return; and allow the caller to > handle failure.
That it dies on failure is documented, and the caller can catch that in the normal eval/$@ way Show quoted text
> 2) print FILE $with x $bytes; is bad: > it uses $bytes amount of memory
Fixed. Thankyou for the excuse to use a C-style for-loop :-) Show quoted text
> for (1 .. $bytes) { > print {$fh} $single_byte; > }
IIRC that would also allocate $bytes memory on some perls, hence a C-style loop. Show quoted text
> 3) close() is not checked for success (try this as a user who is over > their quota. every thing will work fine until close() fails > with over quota errno)
Fixed. Show quoted text
> 4) in overwrite_and_unlink() you shouldn't do the unlink unless the > overwrite returned successfully
If there are any errors during overwrite, it'll die and so never get to the unlink.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.