summaryrefslogtreecommitdiff
path: root/src/import/export-tar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/export-tar.c')
-rw-r--r--src/import/export-tar.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index 9e7c0eaa9d..ed546769f3 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -6,11 +6,11 @@
#include "btrfs-util.h"
#include "export-tar.h"
#include "fd-util.h"
-#include "fileio.h"
#include "import-common.h"
#include "process-util.h"
#include "ratelimit.h"
#include "string-util.h"
+#include "tmpfile-util.h"
#include "util.h"
#define COPY_BUFFER_SIZE (16*1024)
@@ -88,17 +88,20 @@ int tar_export_new(
assert(ret);
- e = new0(TarExport, 1);
+ e = new(TarExport, 1);
if (!e)
return -ENOMEM;
- e->output_fd = e->tar_fd = -1;
- e->on_finished = on_finished;
- e->userdata = userdata;
- e->quota_referenced = (uint64_t) -1;
+ *e = (TarExport) {
+ .output_fd = -1,
+ .tar_fd = -1,
+ .on_finished = on_finished,
+ .userdata = userdata,
+ .quota_referenced = (uint64_t) -1,
+ .last_percent = (unsigned) -1,
+ };
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
- e->last_percent = (unsigned) -1;
if (event)
e->event = sd_event_ref(event);
@@ -138,6 +141,26 @@ static void tar_export_report_progress(TarExport *e) {
e->last_percent = percent;
}
+static int tar_export_finish(TarExport *e) {
+ int r;
+
+ assert(e);
+ assert(e->tar_fd >= 0);
+
+ if (e->tar_pid > 0) {
+ r = wait_for_terminate_and_check("tar", e->tar_pid, WAIT_LOG);
+ e->tar_pid = 0;
+ if (r < 0)
+ return r;
+ if (r != EXIT_SUCCESS)
+ return -EPROTO;
+ }
+
+ e->tar_fd = safe_close(e->tar_fd);
+
+ return 0;
+}
+
static int tar_export_process(TarExport *e) {
ssize_t l;
int r;
@@ -153,7 +176,7 @@ static int tar_export_process(TarExport *e) {
e->tried_splice = true;
} else if (l == 0) {
- r = 0;
+ r = tar_export_finish(e);
goto finish;
} else {
e->written_uncompressed += l;
@@ -169,7 +192,7 @@ static int tar_export_process(TarExport *e) {
uint8_t input[COPY_BUFFER_SIZE];
if (e->eof) {
- r = 0;
+ r = tar_export_finish(e);
goto finish;
}