X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-File-KDBX;a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FKey%2FFile.pm;h=0b6093f985771182f1d9f048f695223c39e27f99;hp=335b31e367fdf91bff45a4a13a69701577fd9826;hb=796fdad82448b51f9c990ca461df647341a84b7e;hpb=84a35b3fe4421abbe930586dd3a214cbb15da9b7
diff --git a/lib/File/KDBX/Key/File.pm b/lib/File/KDBX/Key/File.pm
index 335b31e..0b6093f 100644
--- a/lib/File/KDBX/Key/File.pm
+++ b/lib/File/KDBX/Key/File.pm
@@ -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;
}
}