]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/Plugin.pm
storage: get subdirectory files: read .comment files for comments
[pve-storage.git] / PVE / Storage / Plugin.pm
index e6cd99c0611f32540cf0babe00bff40fada23a81..00ce9cb3c1230950906b1d358cd7c4fb552ec729 100644 (file)
@@ -19,6 +19,8 @@ use base qw(PVE::SectionConfig);
 
 use constant COMPRESSOR_RE => 'gz|lzo|zst';
 
+use constant COMMENT_EXT => ".comment";
+
 our @COMMON_TAR_FLAGS = qw(
     --one-file-system
     -p --sparse --numeric-owner --acls
@@ -783,6 +785,12 @@ sub file_size_info {
 
     my $st = File::stat::stat($filename);
 
+    if (!defined($st)) {
+       my $extramsg = -l $filename ? ' - dangling symlink?' : '';
+       warn "failed to stat '$filename'$extramsg\n";
+       return undef;
+    }
+
     if (S_ISDIR($st->mode)) {
        return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1;
     }
@@ -882,6 +890,10 @@ sub volume_snapshot_delete {
     return undef;
 }
 
+sub volume_snapshot_needs_fsfreeze {
+
+    return 0;
+}
 sub storage_can_replicate {
     my ($class, $scfg, $storeid, $format) = @_;
 
@@ -977,8 +989,18 @@ my $get_subdir_files = sub {
 
     my $res = [];
 
+    my $has_comment = {};
+
     foreach my $fn (<$path/*>) {
 
+       if (COMMENT_EXT eq substr($fn, -length(COMMENT_EXT))) {
+           my $real_fn = substr($fn, 0, length($fn) -  length(COMMENT_EXT));
+           if (!defined($has_comment->{$real_fn})) {
+               $has_comment->{$real_fn} = (-f $fn);
+           }
+           next; # we do not need to do anything with comments themselves
+       }
+
        my $st = File::stat::stat($fn);
 
        next if (!$st || S_ISDIR($st->mode));
@@ -998,6 +1020,7 @@ my $get_subdir_files = sub {
        } elsif ($tt eq 'backup') {
            next if defined($vmid) && $fn !~  m/\S+-$vmid-\S+/;
            next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!;
+           my $original = $fn;
            my $format = $2;
            $fn = $1;
            $info = { volid => "$sid:backup/$fn", format => $format };
@@ -1010,6 +1033,16 @@ my $get_subdir_files = sub {
                $info->{vmid} = $vmid // $1;
            }
 
+           my $comment_fn = $original.COMMENT_EXT;
+           if (!defined($has_comment->{$original})) {
+               $has_comment->{$original} = (-f $comment_fn);
+           }
+
+           if ($has_comment->{$original}) {
+               my $comment = PVE::Tools::file_read_firstline($comment_fn);
+               $info->{comment} = $comment if defined($comment);
+           }
+
        } elsif ($tt eq 'snippets') {
 
            $info = {