]>
git.proxmox.com Git - systemd.git/blob - src/shared/import-util.c
2 This file is part of systemd.
4 Copyright 2015 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "alloc-util.h"
24 #include "btrfs-util.h"
25 #include "import-util.h"
28 #include "path-util.h"
29 #include "string-table.h"
30 #include "string-util.h"
33 int import_url_last_component(const char *url
, char **ret
) {
37 e
= strchrnul(url
, '?');
39 while (e
> url
&& e
[-1] == '/')
43 while (p
> url
&& p
[-1] != '/')
49 s
= strndup(p
, e
- p
);
58 int import_url_change_last_component(const char *url
, const char *suffix
, char **ret
) {
65 e
= strchrnul(url
, '?');
67 while (e
> url
&& e
[-1] == '/')
70 while (e
> url
&& e
[-1] != '/')
76 s
= new(char, (e
- url
) + strlen(suffix
) + 1);
80 strcpy(mempcpy(s
, url
, e
- url
), suffix
);
85 static const char* const import_verify_table
[_IMPORT_VERIFY_MAX
] = {
86 [IMPORT_VERIFY_NO
] = "no",
87 [IMPORT_VERIFY_CHECKSUM
] = "checksum",
88 [IMPORT_VERIFY_SIGNATURE
] = "signature",
91 DEFINE_STRING_TABLE_LOOKUP(import_verify
, ImportVerify
);
93 int tar_strip_suffixes(const char *name
, char **ret
) {
97 e
= endswith(name
, ".tar");
99 e
= endswith(name
, ".tar.xz");
101 e
= endswith(name
, ".tar.gz");
103 e
= endswith(name
, ".tar.bz2");
105 e
= endswith(name
, ".tgz");
112 s
= strndup(name
, e
- name
);
120 int raw_strip_suffixes(const char *p
, char **ret
) {
122 static const char suffixes
[] =
131 _cleanup_free_
char *q
= NULL
;
139 bool changed
= false;
141 NULSTR_FOREACH(sfx
, suffixes
) {
144 e
= endswith(q
, sfx
);
161 int import_assign_pool_quota_and_warn(const char *path
) {
164 r
= btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
166 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.");
170 return log_error_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
172 log_info("Set up default quota hierarchy for /var/lib/machines.");
174 r
= btrfs_subvol_auto_qgroup(path
, 0, true);
176 log_debug_errno(r
, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path
);
180 return log_error_errno(r
, "Failed to set up default quota hierarchy for %s: %m", path
);
182 log_info("Set up default quota hierarchy for %s.", path
);