]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/import-tar.c
util-lib: move a number of fs operations into fs-util.[ch]
[thirdparty/systemd.git] / src / import / import-tar.c
index c5346ca2b04e5472b076e884b7db0e01c07ad8a2..64eb5ccd8337d4835a599eac54afeb7a9f136214 100644 (file)
 
 #include "sd-daemon.h"
 #include "sd-event.h"
-#include "util.h"
-#include "path-util.h"
+
 #include "btrfs-util.h"
 #include "copy.h"
-#include "mkdir.h"
-#include "rm-rf.h"
-#include "ratelimit.h"
-#include "machine-pool.h"
-#include "qcow2-util.h"
-#include "import-compress.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
+#include "hostname-util.h"
 #include "import-common.h"
+#include "import-compress.h"
 #include "import-tar.h"
+#include "io-util.h"
+#include "machine-pool.h"
+#include "mkdir.h"
+#include "path-util.h"
+#include "process-util.h"
+#include "qcow2-util.h"
+#include "ratelimit.h"
+#include "rm-rf.h"
+#include "string-util.h"
+#include "util.h"
 
 struct TarImport {
         sd_event *event;
@@ -87,8 +95,7 @@ TarImport* tar_import_unref(TarImport *i) {
         }
 
         if (i->temp_path) {
-                (void) btrfs_subvol_remove(i->temp_path);
-                (void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL);
+                (void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
                 free(i->temp_path);
         }
 
@@ -197,17 +204,14 @@ static int tar_import_finish(TarImport *i) {
                         return r;
         }
 
-        if (i->force_local) {
-                (void) btrfs_subvol_remove(i->final_path);
-                (void) rm_rf(i->final_path, REMOVE_ROOT|REMOVE_PHYSICAL);
-        }
+        if (i->force_local)
+                (void) rm_rf(i->final_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
 
         r = rename_noreplace(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path);
         if (r < 0)
                 return log_error_errno(r, "Failed to move image into place: %m");
 
-        free(i->temp_path);
-        i->temp_path = NULL;
+        i->temp_path = mfree(i->temp_path);
 
         return 0;
 }
@@ -225,7 +229,7 @@ static int tar_import_fork_tar(TarImport *i) {
         if (!i->final_path)
                 return log_oom();
 
-        r = tempfn_random(i->final_path, &i->temp_path);
+        r = tempfn_random(i->final_path, NULL, &i->temp_path);
         if (r < 0)
                 return log_oom();
 
@@ -237,6 +241,8 @@ static int tar_import_fork_tar(TarImport *i) {
                         return log_error_errno(errno, "Failed to create directory %s: %m", i->temp_path);
         } else if (r < 0)
                 return log_error_errno(errno, "Failed to create subvolume %s: %m", i->temp_path);
+        else
+                (void) import_assign_pool_quota_and_warn(i->temp_path);
 
         i->tar_fd = import_fork_tar_x(i->temp_path, &i->tar_pid);
         if (i->tar_fd < 0)