1IO::AtomicFile(3)     User Contributed Perl Documentation    IO::AtomicFile(3)
2
3
4

NAME

6       IO::AtomicFile - write a file which is updated atomically
7

SYNOPSIS

9           use IO::AtomicFile;
10
11           ### Write a temp file, and have it install itself when closed:
12           my $FH = IO::AtomicFile->open("bar.dat", "w");
13           print $FH "Hello!\n";
14           $FH->close ⎪⎪ die "couldn't install atomic file: $!";
15
16           ### Write a temp file, but delete it before it gets installed:
17           my $FH = IO::AtomicFile->open("bar.dat", "w");
18           print $FH "Hello!\n";
19           $FH->delete;
20
21           ### Write a temp file, but neither install it nor delete it:
22           my $FH = IO::AtomicFile->open("bar.dat", "w");
23           print $FH "Hello!\n";
24           $FH->detach;
25

DESCRIPTION

27       This module is intended for people who need to update files reliably in
28       the face of unexpected program termination.
29
30       For example, you generally don't want to be halfway in the middle of
31       writing /etc/passwd and have your program terminate!  Even the act of
32       writing a single scalar to a filehandle is not atomic.
33
34       But this module gives you true atomic updates, via rename().  When you
35       open a file /foo/bar.dat via this module, you are actually opening a
36       temporary file /foo/bar.dat..TMP, and writing your output there.   The
37       act of closing this file (either explicitly via close(), or implicitly
38       via the destruction of the object) will cause rename() to be called...
39       therefore, from the point of view of the outside world, the file's con‐
40       tents are updated in a single time quantum.
41
42       To ensure that problems do not go undetected, the "close" method done
43       by the destructor will raise a fatal exception if the rename() fails.
44       The explicit close() just returns undef.
45
46       You can also decide at any point to trash the file you've been build‐
47       ing.
48

AUTHOR

50       Primary Maintainer
51
52       David F. Skoll (dfs@roaringpenguin.com).
53
54       Original Author
55
56       Eryq (eryq@zeegee.com).  President, ZeeGee Software Inc
57       (http://www.zeegee.com).
58

REVISION

60       $Revision: 1.2 $
61
62
63
64perl v5.8.8                       2005-02-10                 IO::AtomicFile(3)
Impressum