[pve-devel] r4963 - pve-common/trunk
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue Aug 10 14:06:16 CEST 2010
Author: dietmar
Date: 2010-08-10 12:06:16 +0000 (Tue, 10 Aug 2010)
New Revision: 4963
Modified:
pve-common/trunk/ChangeLog
pve-common/trunk/INotify.pm
Log:
(parse_ccache_options): new perm option (set file perm (example
0664));
(write_file): do not use PVE::AtomicFile, correctly set file
permissions
Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog 2010-08-10 10:03:24 UTC (rev 4962)
+++ pve-common/trunk/ChangeLog 2010-08-10 12:06:16 UTC (rev 4963)
@@ -1,4 +1,8 @@
2010-08-10 Proxmox Support Team <support at proxmox.com>
* INotify.pm (parse_ccache_options): new shadow option
+ (parse_ccache_options): new perm option (set file perm (example
+ 0664));
+ (write_file): do not use PVE::AtomicFile, correctly set file
+ permissions
Modified: pve-common/trunk/INotify.pm
===================================================================
--- pve-common/trunk/INotify.pm 2010-08-10 10:03:24 UTC (rev 4962)
+++ pve-common/trunk/INotify.pm 2010-08-10 12:06:16 UTC (rev 4963)
@@ -1,16 +1,20 @@
package PVE::INotify;
+# fixme: maybe we do not need update_file() ?
+
use strict;
use IO::File;
use IO::Dir;
-use PVE::AtomicFile;
use File::stat;
use File::Basename;
-use Fcntl ':flock';
+use Fcntl qw(:DEFAULT :flock);
use PVE::SafeSyslog;
use Storable qw(dclone);
use Linux::Inotify2;
+use base 'Exporter';
+our @EXPORT_OK = qw(read_file write_file);
+
my $ccache;
my $ccachemap;
my $ccacheregex;
@@ -88,22 +92,33 @@
$realname = $shadow;
}
- my $fh = PVE::AtomicFile->open($realname, "w") ||
- die "unable to open file '$realname' for writing - $! :ERROR";
+ my $perm = $ccinfo->{perm} || 0644;
+ my $tmpname = "$realname.tmp.$$";
+
my $res;
+ eval {
+ my $fh = IO::File->new($tmpname, O_WRONLY|O_CREAT, $perm);
+ die "unable to open file '$tmpname' - $!\n" if !$fh;
- eval {
$res = &$writer ($filename, $fh, $data);
+
+ die "closing file '$tmpname' failed - $!\n" unless close $fh;
};
+ my $err = $@;
$ccinfo->{version} = undef;
- my $err = $@;
- $fh->detach() if $err;
- $fh->close(1);
+ if ($err) {
+ unlink $tmpname;
+ die $err;
+ }
- die $err if $err;
+ if (!rename($tmpname, $realname)) {
+ my $msg = "close (rename) atomic file '$filename' failed: $!\n";
+ unlink $tmpname;
+ die $msg;
+ }
my $diff;
if ($shadow && $full) {
@@ -276,6 +291,8 @@
$ccinfo->{$opt} = $v;
} elsif ($opt eq 'shadow') {
$ccinfo->{$opt} = $v;
+ } elsif ($opt eq 'perm') {
+ $ccinfo->{$opt} = $v;
} elsif ($opt eq 'noclone') {
# noclone flag for large read-only data chunks like aplinfo
$ccinfo->{$opt} = $v;
More information about the pve-devel
mailing list