]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/import-tar.c
shared: add process-util.[ch]
[thirdparty/systemd.git] / src / import / import-tar.c
index dd95575660b6ebac2f4a2bc841e64507eb81b690..12701bfcefb3ac4f4c85632e02915457c537617a 100644 (file)
 #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 "import-common.h"
 #include "import-tar.h"
+#include "process-util.h"
 
 struct TarImport {
         sd_event *event;
@@ -86,8 +88,7 @@ TarImport* tar_import_unref(TarImport *i) {
         }
 
         if (i->temp_path) {
-                (void) btrfs_subvol_remove(i->temp_path);
-                (void) rm_rf_dangerous(i->temp_path, false, true, false);
+                (void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
                 free(i->temp_path);
         }
 
@@ -196,13 +197,12 @@ static int tar_import_finish(TarImport *i) {
                         return r;
         }
 
-        if (i->force_local) {
-                (void) btrfs_subvol_remove(i->final_path);
-                (void) rm_rf_dangerous(i->final_path, false, true, false);
-        }
+        if (i->force_local)
+                (void) rm_rf(i->final_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
 
-        if (renameat2(AT_FDCWD, i->temp_path, AT_FDCWD, i->final_path, RENAME_NOREPLACE) < 0)
-                return log_error_errno(errno, "Failed to move image into place: %m");
+        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;