]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/import-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2015 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "alloc-util.h"
25 #include "btrfs-util.h"
26 #include "import-util.h"
29 #include "path-util.h"
30 #include "string-table.h"
31 #include "string-util.h"
34 int import_url_last_component(const char *url
, char **ret
) {
38 e
= strchrnul(url
, '?');
40 while (e
> url
&& e
[-1] == '/')
44 while (p
> url
&& p
[-1] != '/')
50 s
= strndup(p
, e
- p
);
59 int import_url_change_last_component(const char *url
, const char *suffix
, char **ret
) {
66 e
= strchrnul(url
, '?');
68 while (e
> url
&& e
[-1] == '/')
71 while (e
> url
&& e
[-1] != '/')
77 s
= new(char, (e
- url
) + strlen(suffix
) + 1);
81 strcpy(mempcpy(s
, url
, e
- url
), suffix
);
86 static const char* const import_verify_table
[_IMPORT_VERIFY_MAX
] = {
87 [IMPORT_VERIFY_NO
] = "no",
88 [IMPORT_VERIFY_CHECKSUM
] = "checksum",
89 [IMPORT_VERIFY_SIGNATURE
] = "signature",
92 DEFINE_STRING_TABLE_LOOKUP(import_verify
, ImportVerify
);
94 int tar_strip_suffixes(const char *name
, char **ret
) {
98 e
= endswith(name
, ".tar");
100 e
= endswith(name
, ".tar.xz");
102 e
= endswith(name
, ".tar.gz");
104 e
= endswith(name
, ".tar.bz2");
106 e
= endswith(name
, ".tgz");
113 s
= strndup(name
, e
- name
);
121 int raw_strip_suffixes(const char *p
, char **ret
) {
123 static const char suffixes
[] =
132 _cleanup_free_
char *q
= NULL
;
140 bool changed
= false;
142 NULSTR_FOREACH(sfx
, suffixes
) {
145 e
= endswith(q
, sfx
);
162 int import_assign_pool_quota_and_warn(const char *path
) {
165 r
= btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
167 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.");
171 return log_error_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
173 log_info("Set up default quota hierarchy for /var/lib/machines.");
175 r
= btrfs_subvol_auto_qgroup(path
, 0, true);
177 log_debug_errno(r
, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path
);
181 return log_error_errno(r
, "Failed to set up default quota hierarchy for %s: %m", path
);
183 log_info("Set up default quota hierarchy for %s.", path
);