home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_8d0e961ce39419293e00dc99f8e91cd6
< prev
next >
Wrap
Text File
|
2000-03-23
|
4KB
|
104 lines
<HTML>
<HEAD>
<TITLE>IO::AtomicFile - write a file which is updated atomically</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> IO::AtomicFile - write a file which is updated atomically</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#author">AUTHOR</A></LI>
<LI><A HREF="#revision">REVISION</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>IO::AtomicFile - write a file which is updated atomically</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use IO::AtomicFile;
</PRE>
<PRE>
# Write a temp file, and have it install itself when closed:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!\n";
$FH->close || die "couldn't install atomic file: $!";</PRE>
<PRE>
# Write a temp file, but delete it before it gets installed:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!\n";
$FH->delete;</PRE>
<PRE>
# Write a temp file, but neither install it nor delete it:
my $FH = IO::AtomicFile->open("bar.dat", "w");
print $FH "Hello!\n";
$FH->detach;</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>This module is intended for people who need to update files
reliably in the face of unexpected program termination.</P>
<P>For example, you generally don't want to be halfway in the middle of
writing <EM>/etc/passwd</EM> and have your program terminate! Even
the act of writing a single scalar to a filehandle is <EM>not</EM> atomic.</P>
<P>But this module gives you true atomic updates, via rename().
When you open a file <EM>/foo/bar.dat</EM> via this module, you are <EM>actually</EM>
opening a temporary file <EM>/foo/bar.dat..TMP</EM>, and writing your
output there. The act of closing this file (either explicitly
via close(), or implicitly via the destruction of the object)
will cause <A HREF="../../../lib/Pod/perlfunc.html#item_rename"><CODE>rename()</CODE></A> to be called... therefore, from the point
of view of the outside world, the file's contents are updated
in a single time quantum.</P>
<P>To ensure that problems do not go undetected, the ``close'' method
done by the destructor will raise a fatal exception if the <A HREF="../../../lib/Pod/perlfunc.html#item_rename"><CODE>rename()</CODE></A>
fails. The explicit <A HREF="../../../lib/Pod/perlfunc.html#item_close"><CODE>close()</CODE></A> just returns undef.</P>
<P>You can also decide at any point to trash the file you've been
building.</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Eryq (<EM><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></EM>).
President, ZeeGee Software Inc (<EM><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></EM>).</P>
<P>
<HR>
<H1><A NAME="revision">REVISION</A></H1>
<P>$Revision: 1.104 $</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> IO::AtomicFile - write a file which is updated atomically</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>