While for sysupdate it's fine to consume a large set of all possible update payloads in a single directory this is not so handy for managing and serving the update payloads. Since this large update folder is not where the build output directly gets written to one has to create copies and later possibly delete this added set of files. Support matching for filenames in subdirectories by having a new **/ match pattern prefix which matches any number of nested subdirectories or no subdirectory at all. For simplicity it's only allowed at the start of a pattern and not a regular wildcard as the rest because the main use case is to descend into subdirectories and only do the pattern matching for the basenames. This way one can create a SHA256SUMS file in the top folder and have it include all update payloads from the release-specific (or arch-specific) subdirectories. Something similar was already supported for directory sources where the match pattern can start with a subdirectory path. Do also support this for SHA256SUMS for parity while we are at it. Having the new wildcard makes mirroring also easier because one does not have to follow the exact subdirectory layout and one can filter by folder instead of by filename. It also makes it possible to point the same transfer files with the new wildcard to either a SHA256SUMS file that uses release-specific (or arch-specific) subdirectories and includes all versions or to a SHA256SUMS file as generated from mkosi that does not use subdirectories because it only has files for a single version. With the upcoming UAPI.16 JSON format we will also be able to encode subdirectories and it makes sense to add this to SHA256SUMS for being able to convert them. It also supports custom URLs for each entry which is more powerful than the (arbitrary) subdirectory feature used here but subdirectories have the advantage that they don't break mirroring. This change also fixes the existing subdirectory handling bugs where everything greater than two subdirectory levels failed to work because rel_joined instead of de->d_name got used, symlinks were followed, and we would continue silently on non-ENOENT errors.
102 lines
3.4 KiB
C
102 lines
3.4 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include "gpt.h"
|
|
#include "sysupdate-forward.h"
|
|
|
|
typedef enum ResourceType {
|
|
RESOURCE_URL_FILE,
|
|
RESOURCE_URL_TAR,
|
|
RESOURCE_TAR,
|
|
RESOURCE_PARTITION,
|
|
RESOURCE_REGULAR_FILE,
|
|
RESOURCE_DIRECTORY,
|
|
RESOURCE_SUBVOLUME,
|
|
_RESOURCE_TYPE_MAX,
|
|
_RESOURCE_TYPE_INVALID = -EINVAL,
|
|
} ResourceType;
|
|
|
|
static inline bool RESOURCE_IS_SOURCE(ResourceType t) {
|
|
return IN_SET(t,
|
|
RESOURCE_URL_FILE,
|
|
RESOURCE_URL_TAR,
|
|
RESOURCE_TAR,
|
|
RESOURCE_REGULAR_FILE,
|
|
RESOURCE_DIRECTORY,
|
|
RESOURCE_SUBVOLUME);
|
|
}
|
|
|
|
static inline bool RESOURCE_IS_TARGET(ResourceType t) {
|
|
return IN_SET(t,
|
|
RESOURCE_PARTITION,
|
|
RESOURCE_REGULAR_FILE,
|
|
RESOURCE_DIRECTORY,
|
|
RESOURCE_SUBVOLUME);
|
|
}
|
|
|
|
/* Returns true for all resources that deal with file system objects, i.e. where we operate on top of the
|
|
* file system layer, instead of below. */
|
|
static inline bool RESOURCE_IS_FILESYSTEM(ResourceType t) {
|
|
return IN_SET(t,
|
|
RESOURCE_TAR,
|
|
RESOURCE_REGULAR_FILE,
|
|
RESOURCE_DIRECTORY,
|
|
RESOURCE_SUBVOLUME);
|
|
}
|
|
|
|
static inline bool RESOURCE_IS_TAR(ResourceType t) {
|
|
return IN_SET(t,
|
|
RESOURCE_TAR,
|
|
RESOURCE_URL_TAR);
|
|
}
|
|
|
|
static inline bool RESOURCE_IS_URL(ResourceType t) {
|
|
return IN_SET(t,
|
|
RESOURCE_URL_TAR,
|
|
RESOURCE_URL_FILE);
|
|
}
|
|
|
|
typedef enum PathRelativeTo {
|
|
/* Please make sure to follow the naming of the corresponding PartitionDesignator enum values,
|
|
* where this makes sense, like for the following three. */
|
|
PATH_RELATIVE_TO_ROOT,
|
|
PATH_RELATIVE_TO_ESP,
|
|
PATH_RELATIVE_TO_XBOOTLDR,
|
|
PATH_RELATIVE_TO_BOOT, /* Refers to $BOOT from the BLS. No direct counterpart in PartitionDesignator */
|
|
PATH_RELATIVE_TO_EXPLICIT,
|
|
_PATH_RELATIVE_TO_MAX,
|
|
_PATH_RELATIVE_TO_INVALID = -EINVAL,
|
|
} PathRelativeTo;
|
|
|
|
typedef struct Resource {
|
|
ResourceType type;
|
|
|
|
/* Where to look for instances, and what to match precisely */
|
|
char *path;
|
|
bool path_auto; /* automatically find root path (only available if target resource, not source resource) */
|
|
PathRelativeTo path_relative_to;
|
|
char **patterns;
|
|
GptPartitionType partition_type;
|
|
bool partition_type_set;
|
|
|
|
/* All instances of this resource we found */
|
|
Instance **instances;
|
|
size_t n_instances;
|
|
|
|
/* If this is a partition resource (RESOURCE_PARTITION), then how many partition slots are currently unassigned, that we can use */
|
|
size_t n_empty;
|
|
} Resource;
|
|
|
|
void resource_destroy(Resource *rr);
|
|
|
|
bool resource_has_glob_directory_pattern(Resource *rr);
|
|
|
|
int resource_load_instances(Resource *rr, bool verify, Hashmap **web_cache);
|
|
|
|
Instance* resource_find_instance(Resource *rr, const char *version);
|
|
|
|
int resource_resolve_path(Resource *rr, const char *root, const char *relative_to_directory, const char *node);
|
|
|
|
DECLARE_STRING_TABLE_LOOKUP(resource_type, ResourceType);
|
|
DECLARE_STRING_TABLE_LOOKUP(path_relative_to, PathRelativeTo);
|