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
40       contents 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
47       building.
48

AUTHOR

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

REVISION

58       $Revision: 1.2 $
59
60
61
62perl v5.28.1                      2015-04-22                 IO::AtomicFile(3)
Impressum