How to detect 'Out of Space' 
Author Message
 How to detect 'Out of Space'

Heres a small script (made up)

open ( FILE, ">test.file" )
print FILE "this is a test...";
close (FILE);

how do I know if the file system created the file?? does close return any
error?

heres a modified version which check to see if the server is out of space:
open( FILE, ">test.file" );
print FILE "test";
clsoe (FILE );
if ( -z "test.file" ) { #SERVER IS OUT OF SPACE, didnt create the file
    #report error and exit
    exit;

Quote:
} esle {

    unlink( "test.file"

Quote:
}

#back to creating the file you wanted:

open ( FILE, ">test.file" )
print FILE "this is a test...";
close (FILE);

The check isnt that good, so i wanted your opinion.



Wed, 10 Dec 2003 20:01:16 GMT  
 How to detect 'Out of Space'

Quote:

>Heres a small script (made up)

>open ( FILE, ">test.file" )
>print FILE "this is a test...";
>close (FILE);

>how do I know if the file system created the file?? does close return any
>error?

All three of those functions (open, print, and close) can return
errors if they can't do their work because there's no enough space
on the filesystem.

  -Greg
--

I have a map of the United States that's actual size
                 -- Steven Wright



Wed, 10 Dec 2003 22:10:15 GMT  
 How to detect 'Out of Space'


Quote:
> Heres a small script (made up)

> open ( FILE, ">test.file" )
> print FILE "this is a test...";
> close (FILE);

> how do I know if the file system created the file?? does close return any
> error?

Yes. That's why you should check the success not only of open(), but
also of close() if you're closing a file that you opened for writing to;
it can tell you whether you're out of space. (You can also check the
return value of each print(), if you want.)

Quote:
> heres a modified version which check to see if the server is out of space:
> open( FILE, ">test.file" );
> print FILE "test";
> clsoe (FILE );
> if ( -z "test.file" ) { #SERVER IS OUT OF SPACE, didnt create the file
>     #report error and exit
>     exit;
> } esle {
>     unlink( "test.file"
> }

That will only check whether the machine is completely out of space. But
imagine that it only has 100 KB left, then you can successully create
your dinky "test" file, but if you later try to write 200 KB to disk,
half of your data will end up in never-never-land. So this is a bad
test. (Never mind that the machine's disk might fill up between the test
and the time you attempt to actually write to the file.)

Cheers,
Philip
--

Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.



Wed, 10 Dec 2003 22:28:37 GMT  
 How to detect 'Out of Space'
[Posted and mailed]



Quote:
> Heres a small script (made up)

> open ( FILE, ">test.file" )
> print FILE "this is a test...";
> close (FILE);

> how do I know if the file system created the file?? does close return any
> error?

It did, you just ignored it.  The return value from open() will tell you
if the file was created.  The canonical way of checking this is:

        open(FILE, ">test.file") || die "Cannot create: $!";

--
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*

"If you rush a Miracle Man,     for details, see http://geeksalad.org    
        you get rotten Miracles." --Miracle Max, The Princess Bride



Thu, 11 Dec 2003 02:06:13 GMT  
 How to detect 'Out of Space'

Quote:

> The return value from open() will tell you if the file was created.

And the return value from close() will tell you whether you managed to
write all of your data to it :)

Quote:
> The canonical way of checking this is:

>    open(FILE, ">test.file") || die "Cannot create: $!";

Well, I would argue that the form with 'or die' and with parentheses is
perhaps more common, so either might be called "canonical". YMMV,
TMTOWTDI, HAND.

Cheers,
Philip
--

Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.



Fri, 12 Dec 2003 15:26:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. using 'use strict' to detect errors

2. Removing unnessary spaces 'blanks'

3. How to bind 'Back Space' event

4. Detecting IO redirection while ssh'd on remote machine

5. select doesn't detect pipe close

6. failed to set lock 'Deadlock situation detected

7. AUTO-DETECT VISITORS' BROWSERS

8. AUTO-DETECT VISITORS' BROWSERS

9. What is pseudorandommy @chars=('a'..'z','A'..'Z','0'..'9','_');

10. Space to run Cgi's or perl

11. HTTP::Daemon doesn't handle file names containing spaces

12. Web space available, $$$ reasonable, also Business Opp's

 

 
Powered by phpBB® Forum Software