/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2015 Lennart Poettering
-***/
#include <linux/fs.h>
#include "ratelimit.h"
#include "rm-rf.h"
#include "string-util.h"
+#include "tmpfile-util.h"
#include "util.h"
struct TarImport {
char *local;
bool force_local;
bool read_only;
- bool grow_machine_directory;
char *temp_path;
char *final_path;
ImportCompress compress;
- uint64_t written_since_last_grow;
-
sd_event_source *input_event_source;
uint8_t buffer[16*1024];
void *userdata) {
_cleanup_(tar_import_unrefp) TarImport *i = NULL;
+ _cleanup_free_ char *root = NULL;
int r;
assert(ret);
- i = new0(TarImport, 1);
+ root = strdup(image_root ?: "/var/lib/machines");
+ if (!root)
+ return -ENOMEM;
+
+ i = new(TarImport, 1);
if (!i)
return -ENOMEM;
- i->input_fd = i->tar_fd = -1;
- i->on_finished = on_finished;
- i->userdata = userdata;
+ *i = (TarImport) {
+ .input_fd = -1,
+ .tar_fd = -1,
+ .on_finished = on_finished,
+ .userdata = userdata,
+ .last_percent = (unsigned) -1,
+ .image_root = TAKE_PTR(root),
+ };
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
- i->last_percent = (unsigned) -1;
-
- i->image_root = strdup(image_root ?: "/var/lib/machines");
- if (!i->image_root)
- return -ENOMEM;
-
- i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
if (event)
i->event = sd_event_ref(event);
i->tar_pid = 0;
if (r < 0)
return r;
+ if (r != EXIT_SUCCESS)
+ return -EPROTO;
}
+ r = import_mangle_os_tree(i->temp_path);
+ if (r < 0)
+ return r;
+
if (i->read_only) {
r = import_make_read_only(i->temp_path);
if (r < 0)
assert(!i->temp_path);
assert(i->tar_fd < 0);
- i->final_path = strjoin(i->image_root, "/", i->local);
+ i->final_path = path_join(i->image_root, i->local);
if (!i->final_path)
return log_oom();
TarImport *i = userdata;
int r;
- if (i->grow_machine_directory && i->written_since_last_grow >= GROW_INTERVAL_BYTES) {
- i->written_since_last_grow = 0;
- grow_machine_directory();
- }
-
r = loop_write(i->tar_fd, p, sz, false);
if (r < 0)
return r;
i->written_uncompressed += sz;
- i->written_since_last_grow += sz;
return 0;
}