#include <sys/types.h>
+typedef enum ImportFlags {
+ IMPORT_FORCE = 1 << 0, /* replace existing image */
+ IMPORT_READ_ONLY = 1 << 1, /* make generated image read-only */
+
+ IMPORT_FLAGS_MASK = IMPORT_FORCE|IMPORT_READ_ONLY,
+} ImportFlags;
+
int import_make_read_only_fd(int fd);
int import_make_read_only(const char *path);
void *userdata;
char *local;
- bool force_local;
- bool read_only;
+ ImportFlags flags;
char *temp_path;
char *final_path;
(void) copy_xattr(i->input_fd, i->output_fd);
}
- if (i->read_only) {
+ if (i->flags & IMPORT_READ_ONLY) {
r = import_make_read_only_fd(i->output_fd);
if (r < 0)
return r;
}
- if (i->force_local)
+ if (i->flags & IMPORT_FORCE)
(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);
return raw_import_process(i);
}
-int raw_import_start(RawImport *i, int fd, const char *local, bool force_local, bool read_only) {
+int raw_import_start(RawImport *i, int fd, const char *local, ImportFlags flags) {
int r;
assert(i);
assert(fd >= 0);
assert(local);
+ assert(!(flags & ~IMPORT_FLAGS_MASK));
if (!hostname_is_valid(local, 0))
return -EINVAL;
r = free_and_strdup(&i->local, local);
if (r < 0)
return r;
- i->force_local = force_local;
- i->read_only = read_only;
+
+ i->flags = flags;
if (fstat(fd, &i->st) < 0)
return -errno;
#include "sd-event.h"
+#include "import-common.h"
#include "import-util.h"
#include "macro.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(RawImport*, raw_import_unref);
-int raw_import_start(RawImport *i, int fd, const char *local, bool force_local, bool read_only);
+int raw_import_start(RawImport *i, int fd, const char *local, ImportFlags flags);
void *userdata;
char *local;
- bool force_local;
- bool read_only;
+ ImportFlags flags;
char *temp_path;
char *final_path;
if (r < 0)
return r;
- if (i->read_only) {
+ if (i->flags & IMPORT_READ_ONLY) {
r = import_make_read_only(i->temp_path);
if (r < 0)
return r;
}
- if (i->force_local)
+ if (i->flags & IMPORT_FORCE)
(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);
return tar_import_process(i);
}
-int tar_import_start(TarImport *i, int fd, const char *local, bool force_local, bool read_only) {
+int tar_import_start(TarImport *i, int fd, const char *local, ImportFlags flags) {
int r;
assert(i);
assert(fd >= 0);
assert(local);
+ assert(!(flags & ~IMPORT_FLAGS_MASK));
if (!hostname_is_valid(local, 0))
return -EINVAL;
r = free_and_strdup(&i->local, local);
if (r < 0)
return r;
- i->force_local = force_local;
- i->read_only = read_only;
+
+ i->flags = flags;
if (fstat(fd, &i->st) < 0)
return -errno;
#include "sd-event.h"
+#include "import-common.h"
#include "import-util.h"
#include "macro.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(TarImport*, tar_import_unref);
-int tar_import_start(TarImport *import, int fd, const char *local, bool force_local, bool read_only);
+int tar_import_start(TarImport *import, int fd, const char *local, ImportFlags flags);
#include "string-util.h"
#include "verbs.h"
-static bool arg_force = false;
-static bool arg_read_only = false;
static const char *arg_image_root = "/var/lib/machines";
+static ImportFlags arg_import_flags = 0;
static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
log_notice("Transfer aborted.");
"Local image name '%s' is not valid.",
local);
- if (!arg_force) {
+ if (!FLAGS_SET(arg_import_flags, IMPORT_FORCE)) {
r = image_find(IMAGE_MACHINE, local, NULL, NULL);
if (r < 0) {
if (r != -ENOENT)
if (r < 0)
return log_error_errno(r, "Failed to allocate importer: %m");
- r = tar_import_start(import, fd, local, arg_force, arg_read_only);
+ r = tar_import_start(import, fd, local, arg_import_flags);
if (r < 0)
return log_error_errno(r, "Failed to import image: %m");
"Local image name '%s' is not valid.",
local);
- if (!arg_force) {
+ if (!FLAGS_SET(arg_import_flags, IMPORT_FORCE)) {
r = image_find(IMAGE_MACHINE, local, NULL, NULL);
if (r < 0) {
if (r != -ENOENT)
if (r < 0)
return log_error_errno(r, "Failed to allocate importer: %m");
- r = raw_import_start(import, fd, local, arg_force, arg_read_only);
+ r = raw_import_start(import, fd, local, arg_import_flags);
if (r < 0)
return log_error_errno(r, "Failed to import image: %m");
return version();
case ARG_FORCE:
- arg_force = true;
+ arg_import_flags |= IMPORT_FORCE;
break;
case ARG_IMAGE_ROOT:
break;
case ARG_READ_ONLY:
- arg_read_only = true;
+ arg_import_flags |= IMPORT_READ_ONLY;
break;
case '?':