{"id":7265,"date":"2022-12-20T19:36:03","date_gmt":"2022-12-20T22:36:03","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/ioatomicfile-man3\/"},"modified":"2022-12-20T19:36:03","modified_gmt":"2022-12-20T22:36:03","slug":"ioatomicfile-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/ioatomicfile-man3\/","title":{"rendered":"IO::AtomicFile (man3)"},"content":{"rendered":"<h1 align=\"center\">IO::AtomicFile<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#METHODS\">METHODS<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#CONTRIBUTORS\">CONTRIBUTORS<\/a><br \/> <a href=\"#COPYRIGHT &#038; LICENSE\">COPYRIGHT &#038; LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">IO::AtomicFile \u2212 write a file which is updated atomically<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use strict; <br \/> use warnings; <br \/> use feature &#8216;say&#8217;; <br \/> use IO::AtomicFile; <br \/> # Write a temp file, and have it install itself when closed: <br \/> my $fh = IO::AtomicFile\u2212>open(&#8220;bar.dat&#8221;, &#8220;w&#8221;); <br \/> $fh\u2212>say(&#8220;Hello!&#8221;); <br \/> $fh\u2212>close || die &#8220;couldn&#8217;t install atomic file: $!&#8221;; <br \/> # Write a temp file, but delete it before it gets installed: <br \/> my $fh = IO::AtomicFile\u2212>open(&#8220;bar.dat&#8221;, &#8220;w&#8221;); <br \/> $fh\u2212>say(&#8220;Hello!&#8221;); <br \/> $fh\u2212>delete; <br \/> # Write a temp file, but neither install it nor delete it: <br \/> my $fh = IO::AtomicFile\u2212>open(&#8220;bar.dat&#8221;, &#8220;w&#8221;); <br \/> $fh\u2212>say(&#8220;Hello!&#8221;); <br \/> $fh\u2212>detach;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This module is intended for people who need to update files reliably in the face of unexpected program termination.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For example, you generally don\u2019t want to be halfway in the middle of writing <i>\/etc\/passwd<\/i> and have your program terminate! Even the act of writing a single scalar to a filehandle is <i>not<\/i> atomic.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">But this module gives you true atomic updates, via &#8220;rename&#8221;. When you open a file <i>\/foo\/bar.dat<\/i> via this module, you are <i>actually<\/i> opening a temporary file <i>\/foo\/bar.dat..TMP<\/i>, and writing your output there. The act of closing this file (either explicitly via &#8220;close&#8221;, or implicitly via the destruction of the object) will cause &#8220;rename&#8221; to be called&#8230; therefore, from the point of view of the outside world, the file\u2019s contents are updated in a single time quantum.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To ensure that problems do not go undetected, the &#8220;close&#8221; method done by the destructor will raise a fatal exception if the &#8220;rename&#8221; fails. The explicit &#8220;close&#8221; just returns &#8220;undef&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">You can also decide at any point to trash the file you\u2019ve been building.<\/p>\n<h2>METHODS <a name=\"METHODS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">IO::AtomicFile inherits all methods from IO::File and implements the following new ones.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>close<\/b> <br \/> $fh\u2212>close();<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method calls its parent &#8220;close&#8221; in IO::File and then renames its temporary file as the original file name.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>delete<\/b> <br \/> $fh\u2212>delete();<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method calls its parent &#8220;close&#8221; in IO::File and then deletes the temporary file.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>detach<\/b> <br \/> $fh\u2212>detach();<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method calls its parent &#8220;close&#8221; in IO::File. Unlike &#8220;delete&#8221; in IO::AtomicFile it does not then delete the temporary file.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Eryq (<i>eryq@zeegee.com<\/i>). President, ZeeGee Software Inc (<i>http:\/\/www.zeegee.com<\/i>).<\/p>\n<h2>CONTRIBUTORS <a name=\"CONTRIBUTORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Dianne Skoll (<i>dfs@roaringpenguin.com<\/i>).<\/p>\n<h2>COPYRIGHT &#038; LICENSE <a name=\"COPYRIGHT &#038; LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Copyright (c) 1997 Erik (Eryq) Dorfman, ZeeGee Software, Inc. All rights reserved.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This program is free software; you can redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  IO::AtomicFile \u2212 write a file which is updated atomically <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3590,3007],"class_list":["post-7265","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-ioatomicfile","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7265"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7265\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}