#include "dirent-util.h"
#include "discover-image.h"
#include "dissect-image.h"
+#include "errno-list.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
static int portable_changes_add(
PortableChange **changes,
size_t *n_changes,
- PortableChangeType type,
+ int type_or_errno, /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, or errno if negative */
const char *path,
const char *source) {
assert(path);
assert(!changes == !n_changes);
+ if (type_or_errno >= 0)
+ assert(type_or_errno < _PORTABLE_CHANGE_TYPE_MAX);
+ else
+ assert(type_or_errno >= -ERRNO_MAX);
+
if (!changes)
return 0;
}
c[(*n_changes)++] = (PortableChange) {
- .type = type,
+ .type_or_errno = type_or_errno,
.path = TAKE_PTR(p),
.source = TAKE_PTR(s),
};
static int portable_changes_add_with_prefix(
PortableChange **changes,
size_t *n_changes,
- PortableChangeType type,
+ int type_or_errno,
const char *prefix,
const char *path,
const char *source) {
source = prefix_roota(prefix, source);
}
- return portable_changes_add(changes, n_changes, type, path, source);
+ return portable_changes_add(changes, n_changes, type_or_errno, path, source);
}
void portable_changes_free(PortableChange *changes, size_t n_changes) {
[PORTABLE_WRITE] = "write",
};
-DEFINE_STRING_TABLE_LOOKUP(portable_change_type, PortableChangeType);
+DEFINE_STRING_TABLE_LOOKUP(portable_change_type, int);
static const char* const portable_state_table[_PORTABLE_STATE_MAX] = {
[PORTABLE_DETACHED] = "detached",
PORTABLE_REATTACH = 1 << 3,
} PortableFlags;
-typedef enum PortableChangeType {
+/* This enum is anonymous, since we usually store it in an 'int', as we overload it with negative errno
+ * values. */
+enum {
PORTABLE_COPY,
PORTABLE_SYMLINK,
PORTABLE_UNLINK,
PORTABLE_MKDIR,
_PORTABLE_CHANGE_TYPE_MAX,
_PORTABLE_CHANGE_TYPE_INVALID = -EINVAL,
-} PortableChangeType;
+};
typedef enum PortableState {
PORTABLE_DETACHED,
} PortableState;
typedef struct PortableChange {
- int type; /* PortableFileChangeType or negative error number */
+ int type_or_errno; /* PORTABLE_COPY, PORTABLE_SYMLINK, … if positive, errno if negative */
char *path;
char *source;
} PortableChange;
void portable_changes_free(PortableChange *changes, size_t n_changes);
-const char *portable_change_type_to_string(PortableChangeType t) _const_;
-PortableChangeType portable_change_type_from_string(const char *t) _pure_;
+const char *portable_change_type_to_string(int t) _const_;
+int portable_change_type_from_string(const char *t) _pure_;
const char *portable_state_to_string(PortableState t) _const_;
PortableState portable_state_from_string(const char *t) _pure_;
return r;
for (i = 0; i < n_changes; i++) {
+ if (changes[i].type_or_errno < 0)
+ continue;
+
r = sd_bus_message_append(reply, "(sss)",
- portable_change_type_to_string(changes[i].type),
+ portable_change_type_to_string(changes[i].type_or_errno),
changes[i].path,
changes[i].source);
if (r < 0)