X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FKey%2FFile.pm;h=0b6093f985771182f1d9f048f695223c39e27f99;hb=796fdad82448b51f9c990ca461df647341a84b7e;hp=fdf131a0993a2fb6fc86c7cff1495ab9561dc596;hpb=37b09e0f2832514b33de4499a83f22d5ffe7c0a3;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Key/File.pm b/lib/File/KDBX/Key/File.pm index fdf131a..0b6093f 100644 --- a/lib/File/KDBX/Key/File.pm +++ b/lib/File/KDBX/Key/File.pm @@ -23,7 +23,7 @@ our $VERSION = '999.999'; # VERSION $type = $key->type; -Get the type of key file. Can be one of: +Get the type of key file. Can be one of from L: =for :list * C @@ -140,6 +140,7 @@ Write a key file. Available options: * C - Where to save the file (default: value of L) * C - IO handle to write to (overrides C, one of which must be defined) * C - Raw key (default: value of L) +* C - Write to the filepath atomically (default: true) =cut @@ -156,18 +157,24 @@ sub save { my $version = $args{version} // $self->version // 2; my $filepath = $args{filepath} // $self->filepath; my $fh = $args{fh}; + my $atomic = $args{atomic} // 1; my $filepath_temp; if (!openhandle($fh)) { $filepath or throw 'Must specify where to safe the key file to'; - require File::Temp; - ($fh, $filepath_temp) = eval { File::Temp::tempfile("${filepath}-XXXXXX", CLEANUP => 1) }; - if (!$fh or my $err = $@) { - $err //= 'Unknown error'; - throw sprintf('Open file failed (%s): %s', $filepath_temp, $err), - error => $err, - filepath => $filepath_temp; + if ($atomic) { + require File::Temp; + ($fh, $filepath_temp) = eval { File::Temp::tempfile("${filepath}-XXXXXX", UNLINK => 1) }; + if (!$fh or my $err = $@) { + $err //= 'Unknown error'; + throw sprintf('Open file failed (%s): %s', $filepath_temp, $err), + error => $err, + filepath => $filepath_temp; + } + } + else { + open($fh, '>:raw', $filepath) or throw "Open file failed ($filepath): $!", filepath => $filepath; } }