]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/import-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "alloc-util.h"
7 #include "btrfs-util.h"
8 #include "import-util.h"
11 #include "nulstr-util.h"
12 #include "path-util.h"
13 #include "string-table.h"
14 #include "string-util.h"
16 int import_url_last_component(const char *url
, char **ret
) {
20 e
= strchrnul(url
, '?');
22 while (e
> url
&& e
[-1] == '/')
26 while (p
> url
&& p
[-1] != '/')
32 s
= strndup(p
, e
- p
);
40 int import_url_change_last_component(const char *url
, const char *suffix
, char **ret
) {
47 e
= strchrnul(url
, '?');
49 while (e
> url
&& e
[-1] == '/')
52 while (e
> url
&& e
[-1] != '/')
58 s
= new(char, (e
- url
) + strlen(suffix
) + 1);
62 strcpy(mempcpy(s
, url
, e
- url
), suffix
);
67 static const char* const import_verify_table
[_IMPORT_VERIFY_MAX
] = {
68 [IMPORT_VERIFY_NO
] = "no",
69 [IMPORT_VERIFY_CHECKSUM
] = "checksum",
70 [IMPORT_VERIFY_SIGNATURE
] = "signature",
73 DEFINE_STRING_TABLE_LOOKUP(import_verify
, ImportVerify
);
75 int tar_strip_suffixes(const char *name
, char **ret
) {
79 e
= endswith(name
, ".tar");
81 e
= endswith(name
, ".tar.xz");
83 e
= endswith(name
, ".tar.gz");
85 e
= endswith(name
, ".tar.bz2");
87 e
= endswith(name
, ".tgz");
94 s
= strndup(name
, e
- name
);
102 int raw_strip_suffixes(const char *p
, char **ret
) {
104 static const char suffixes
[] =
113 _cleanup_free_
char *q
= NULL
;
121 bool changed
= false;
123 NULSTR_FOREACH(sfx
, suffixes
) {
126 e
= endswith(q
, sfx
);
142 int import_assign_pool_quota_and_warn(const char *path
) {
145 r
= btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
147 log_debug_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines, as directory is not on btrfs or not a subvolume. Ignoring.");
151 return log_error_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
153 log_info("Set up default quota hierarchy for /var/lib/machines.");
155 r
= btrfs_subvol_auto_qgroup(path
, 0, true);
157 log_debug_errno(r
, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path
);
161 return log_error_errno(r
, "Failed to set up default quota hierarchy for %s: %m", path
);
163 log_debug("Set up default quota hierarchy for %s.", path
);