[Melbourne-pm] IO::File with Capture for Quota
Toby Corkindale
toby.corkindale at strategicdata.com.au
Wed Oct 15 20:39:53 PDT 2008
Scott Penrose wrote:
> Hey Guys
>
> I am writing a module at the moment to capture IO::File open to allow me to work out the difference in file size at the start and end of an operation.
>
> My code basically works, but it is a huge hack, and requires a hack on the call to make it work.
>
> Firstly let me show you how I would expect the code to work:
[snip code]
>
> Note that close and DESTROY are partially duplicates for the moment. I would probably complete the work by using a separate method based on the filename (after sync) called from close & destroy. The reason close is important is that it may be used while the object still exists and we want to know as close to closing time as possible.
>
> ALSO NOTE - this captures the wrong size using "-s" as it is before the file is flushed - I can fix those problems easily later.
>
> Right down to my questions:
>
> 1) Is there anyway of getting from a file handle:
> - That it is a file on disk, rather than Socket or Pipe
> - The filename of that file
fstat() works upon filehandles directly, avoiding the needing to keep
the filename around. Might make life easier for you, and also allow you
to work with temporary files that were created and unlinked after open.
> 2) What else would you change - in functions, calls and purpose to make this a useful CPAN module
The name of the module implies that it is meant to be performing quota
management, but the actual action seems to be more like performing a
generic call-back upon close..
If you're actually looking to enforce quotas, wouldn't you need to check
the data written at every write, rather than upon close?
In that case, rather than use '-s' (or fstat()) to get the size, you
could use the return from fnprintf() or similar, which gives you the
number of bytes written.. then you can do something like:
die "Quota exceeded!" unless ($bytes_written <= $remaining_quota);
$remaining_quota -= $bytes_written;
-Toby
--
Strategic Data Pty Ltd
Ph: 03 9340 9000
More information about the Melbourne-pm
mailing list