[pve-devel] [PATCH storage 1/4] api: storage status: pull OCI image to temporary file
Filip Schauer
f.schauer at proxmox.com
Mon Nov 17 18:13:14 CET 2025
Pull the OCI image to a temporary file first. Once it has finished,
rename it, which is an atomic operation. This prevents accidental usage
of an incomplete OCI image file for container creation.
Signed-off-by: Filip Schauer <f.schauer at proxmox.com>
---
src/PVE/API2/Storage/Status.pm | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm
index 5abf53b..96832b9 100644
--- a/src/PVE/API2/Storage/Status.pm
+++ b/src/PVE/API2/Storage/Status.pm
@@ -959,14 +959,26 @@ __PACKAGE__->register_method({
die "storage '$storage' is not configured for content-type 'vztmpl'\n"
if !$scfg->{content}->{vztmpl};
- my $filename = PVE::Storage::normalize_content_filename($reference);
+ my $filename = PVE::Storage::normalize_content_filename($reference) . ".tar";
+ my $tmp_filename = "$filename.tmp.$$";
my $path = PVE::Storage::get_vztmpl_dir($cfg, $storage);
PVE::Storage::activate_storage($cfg, $storage);
+ local $SIG{INT} = sub {
+ unlink "$path/$tmp_filename"
+ or warn "could not cleanup temporary file: $!"
+ if -e "$path/$tmp_filename";
+ die "got interrupted by signal\n";
+ };
+
my $worker = sub {
PVE::Tools::run_command(
- ["skopeo", "copy", "docker://$reference", "oci-archive:$path/$filename.tar"],
+ [
+ "skopeo", "copy", "docker://$reference", "oci-archive:$path/$tmp_filename",
+ ],
);
+ rename("$path/$tmp_filename", "$path/$filename")
+ or die "unable to rename temporary file: $!\n";
};
my $worker_id = PVE::Tools::encode_text($filename); # must not pass : or the like as w-ID
--
2.47.3
More information about the pve-devel
mailing list