]> git.proxmox.com Git - pve-common.git/commitdiff
tempfile: unliked-file fallback
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 2 Nov 2016 11:25:50 +0000 (12:25 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 2 Nov 2016 11:44:35 +0000 (12:44 +0100)
some file systems (eg. ZFS) don't support O_TMPFILE

src/PVE/Tools.pm

index 305e1bf7407fe515fd6a844e7280edec6a203dbf..0be2efee70feb9e34fa8c582ec23ea73a268d307 100644 (file)
@@ -2,7 +2,7 @@ package PVE::Tools;
 
 use strict;
 use warnings;
-use POSIX qw(EINTR EEXIST);
+use POSIX qw(EINTR EEXIST EOPNOTSUPP);
 use IO::Socket::IP;
 use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED);
 use IO::Select;
@@ -1308,8 +1308,13 @@ sub tempfile {
     my $mode = $opts{mode} // O_RDWR;
     $mode |= O_EXCL if !$opts{allow_links};
 
-    my $fh = IO::File->new($dir, $mode | O_TMPFILE, $perm)
-       or die "failed to create tempfile: $!\n";
+    my $fh = IO::File->new($dir, $mode | O_TMPFILE, $perm);
+    if (!$fh && $! == EOPNOTSUPP) {
+       $dir .= "/.tmpfile.$$";
+       $fh = IO::File->new($dir, $mode | O_CREAT | O_EXCL, $perm);
+       unlink($dir) if $fh;
+    }
+    die "failed to create tempfile: $!\n" if !$fh;
     return $fh;
 }