]> git.proxmox.com Git - pve-guest-common.git/commitdiff
PVE::ReplicationState::write_job_state - allow to remove state completely
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Jun 2017 06:13:36 +0000 (08:13 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Jun 2017 06:13:36 +0000 (08:13 +0200)
PVE/ReplicationState.pm

index 6a743a3e5ec358ff69e1bed4d7d96860d71c6f08..8e30e07498505082940e3f89a9834f62b2376a87 100644 (file)
@@ -84,6 +84,7 @@ sub read_job_state {
 }
 
 # update state for a single job
 }
 
 # update state for a single job
+# pass $state = undef to delete the job state completely
 sub write_job_state {
     my ($jobcfg, $state) = @_;
 
 sub write_job_state {
     my ($jobcfg, $state) = @_;
 
@@ -96,8 +97,12 @@ sub write_job_state {
 
        my $stateobj = read_state();
        # Note: tuple ($vmid, $tid) is unique
 
        my $stateobj = read_state();
        # Note: tuple ($vmid, $tid) is unique
-       $stateobj->{$vmid}->{$tid} = $state;
-
+       if (defined($state)) {
+           $stateobj->{$vmid}->{$tid} = $state;
+       } else {
+           delete $stateobj->{$vmid}->{$tid};
+           delete $stateobj->{$vmid} if !%{$stateobj->{$vmid}};
+       }
        PVE::Tools::file_set_contents($state_path, encode_json($stateobj));
     };
 
        PVE::Tools::file_set_contents($state_path, encode_json($stateobj));
     };