]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/import-util.c
43ffd1246ccb1be857ee2596c098628bcc2ca781
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2015 Lennart Poettering
9 #include "alloc-util.h"
10 #include "btrfs-util.h"
11 #include "import-util.h"
14 #include "path-util.h"
15 #include "string-table.h"
16 #include "string-util.h"
19 int import_url_last_component(const char *url
, char **ret
) {
23 e
= strchrnul(url
, '?');
25 while (e
> url
&& e
[-1] == '/')
29 while (p
> url
&& p
[-1] != '/')
35 s
= strndup(p
, e
- p
);
43 int import_url_change_last_component(const char *url
, const char *suffix
, char **ret
) {
50 e
= strchrnul(url
, '?');
52 while (e
> url
&& e
[-1] == '/')
55 while (e
> url
&& e
[-1] != '/')
61 s
= new(char, (e
- url
) + strlen(suffix
) + 1);
65 strcpy(mempcpy(s
, url
, e
- url
), suffix
);
70 static const char* const import_verify_table
[_IMPORT_VERIFY_MAX
] = {
71 [IMPORT_VERIFY_NO
] = "no",
72 [IMPORT_VERIFY_CHECKSUM
] = "checksum",
73 [IMPORT_VERIFY_SIGNATURE
] = "signature",
76 DEFINE_STRING_TABLE_LOOKUP(import_verify
, ImportVerify
);
78 int tar_strip_suffixes(const char *name
, char **ret
) {
82 e
= endswith(name
, ".tar");
84 e
= endswith(name
, ".tar.xz");
86 e
= endswith(name
, ".tar.gz");
88 e
= endswith(name
, ".tar.bz2");
90 e
= endswith(name
, ".tgz");
97 s
= strndup(name
, e
- name
);
105 int raw_strip_suffixes(const char *p
, char **ret
) {
107 static const char suffixes
[] =
116 _cleanup_free_
char *q
= NULL
;
124 bool changed
= false;
126 NULSTR_FOREACH(sfx
, suffixes
) {
129 e
= endswith(q
, sfx
);
145 int import_assign_pool_quota_and_warn(const char *path
) {
148 r
= btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
150 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.");
154 return log_error_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
156 log_info("Set up default quota hierarchy for /var/lib/machines.");
158 r
= btrfs_subvol_auto_qgroup(path
, 0, true);
160 log_debug_errno(r
, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path
);
164 return log_error_errno(r
, "Failed to set up default quota hierarchy for %s: %m", path
);
166 log_info("Set up default quota hierarchy for %s.", path
);