]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/pull-tar.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / import / pull-tar.c
index 375ee778e24a72faa48c74925d16dc6ef0b56676..ed915112455ae3d22a7cf445d785795ec28c1dd3 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -114,6 +115,7 @@ TarPull* tar_pull_unref(TarPull *i) {
         free(i->settings_path);
         free(i->image_root);
         free(i->local);
+
         return mfree(i);
 }
 
@@ -256,7 +258,7 @@ static int tar_pull_make_local_copy(TarPull *i) {
 
                 local_settings = strjoina(i->image_root, "/", i->local, ".nspawn");
 
-                r = copy_file_atomic(i->settings_path, local_settings, 0664, i->force_local, 0);
+                r = copy_file_atomic(i->settings_path, local_settings, 0664, 0, COPY_REFLINK | (i->force_local ? COPY_REPLACE : 0));
                 if (r == -EEXIST)
                         log_warning_errno(r, "Settings file %s already exists, not replacing.", local_settings);
                 else if (r == -ENOENT)
@@ -298,11 +300,9 @@ static void tar_pull_job_on_finished(PullJob *j) {
         if (j == i->settings_job) {
                 if (j->error != 0)
                         log_info_errno(j->error, "Settings file could not be retrieved, proceeding without.");
-        } else if (j->error != 0) {
+        } else if (j->error != 0 && j != i->signature_job) {
                 if (j == i->checksum_job)
                         log_error_errno(j->error, "Failed to retrieve SHA256 checksum, cannot verify. (Try --verify=no?)");
-                else if (j == i->signature_job)
-                        log_error_errno(j->error, "Failed to retrieve signature file, cannot verify. (Try --verify=no?)");
                 else
                         log_error_errno(j->error, "Failed to retrieve image file. (Wrong URL?)");
 
@@ -317,6 +317,13 @@ static void tar_pull_job_on_finished(PullJob *j) {
         if (!tar_pull_is_done(i))
                 return;
 
+        if (i->signature_job && i->checksum_job->style == VERIFICATION_PER_DIRECTORY && i->signature_job->error != 0) {
+                log_error_errno(j->error, "Failed to retrieve signature file, cannot verify. (Try --verify=no?)");
+
+                r = i->signature_job->error;
+                goto finish;
+        }
+
         i->tar_job->disk_fd = safe_close(i->tar_job->disk_fd);
         if (i->settings_job)
                 i->settings_job->disk_fd = safe_close(i->settings_job->disk_fd);
@@ -353,7 +360,7 @@ static void tar_pull_job_on_finished(PullJob *j) {
 
                 r = rename_noreplace(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path);
                 if (r < 0) {
-                        log_error_errno(r, "Failed to rename to final image name: %m");
+                        log_error_errno(r, "Failed to rename to final image name to %s: %m", i->final_path);
                         goto finish;
                 }
 
@@ -362,13 +369,14 @@ static void tar_pull_job_on_finished(PullJob *j) {
                 if (i->settings_job &&
                     i->settings_job->error == 0) {
 
-                        assert(i->settings_temp_path);
-                        assert(i->settings_path);
-
-                        /* Also move the settings file into place, if it exist. Note that we do so only if we also
+                        /* Also move the settings file into place, if it exists. Note that we do so only if we also
                          * moved the tar file in place, to keep things strictly in sync. */
+                        assert(i->settings_temp_path);
 
+                        /* Regenerate final name for this auxiliary file, we might know the etag of the file now, and
+                         * we should incorporate it in the file name if we can */
                         i->settings_path = mfree(i->settings_path);
+
                         r = tar_pull_determine_path(i, ".nspawn", &i->settings_path);
                         if (r < 0)
                                 goto finish;
@@ -379,7 +387,7 @@ static void tar_pull_job_on_finished(PullJob *j) {
 
                         r = rename_noreplace(AT_FDCWD, i->settings_temp_path, AT_FDCWD, i->settings_path);
                         if (r < 0) {
-                                log_error_errno(r, "Failed to rename settings file: %m");
+                                log_error_errno(r, "Failed to rename settings file to %s: %m", i->settings_path);
                                 goto finish;
                         }
 
@@ -547,6 +555,7 @@ int tar_pull_start(
 
         if (i->checksum_job) {
                 i->checksum_job->on_progress = tar_pull_job_on_progress;
+                i->checksum_job->style = VERIFICATION_PER_FILE;
 
                 r = pull_job_begin(i->checksum_job);
                 if (r < 0)