]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/import-util.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "alloc-util.h"
26 #include "btrfs-util.h"
27 #include "import-util.h"
30 #include "path-util.h"
31 #include "string-table.h"
32 #include "string-util.h"
35 int import_url_last_component(const char *url
, char **ret
) {
39 e
= strchrnul(url
, '?');
41 while (e
> url
&& e
[-1] == '/')
45 while (p
> url
&& p
[-1] != '/')
51 s
= strndup(p
, e
- p
);
60 int import_url_change_last_component(const char *url
, const char *suffix
, char **ret
) {
67 e
= strchrnul(url
, '?');
69 while (e
> url
&& e
[-1] == '/')
72 while (e
> url
&& e
[-1] != '/')
78 s
= new(char, (e
- url
) + strlen(suffix
) + 1);
82 strcpy(mempcpy(s
, url
, e
- url
), suffix
);
87 static const char* const import_verify_table
[_IMPORT_VERIFY_MAX
] = {
88 [IMPORT_VERIFY_NO
] = "no",
89 [IMPORT_VERIFY_CHECKSUM
] = "checksum",
90 [IMPORT_VERIFY_SIGNATURE
] = "signature",
93 DEFINE_STRING_TABLE_LOOKUP(import_verify
, ImportVerify
);
95 int tar_strip_suffixes(const char *name
, char **ret
) {
99 e
= endswith(name
, ".tar");
101 e
= endswith(name
, ".tar.xz");
103 e
= endswith(name
, ".tar.gz");
105 e
= endswith(name
, ".tar.bz2");
107 e
= endswith(name
, ".tgz");
114 s
= strndup(name
, e
- name
);
122 int raw_strip_suffixes(const char *p
, char **ret
) {
124 static const char suffixes
[] =
133 _cleanup_free_
char *q
= NULL
;
141 bool changed
= false;
143 NULSTR_FOREACH(sfx
, suffixes
) {
146 e
= endswith(q
, sfx
);
163 int import_assign_pool_quota_and_warn(const char *path
) {
166 r
= btrfs_subvol_auto_qgroup("/var/lib/machines", 0, true);
168 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.");
172 return log_error_errno(r
, "Failed to set up default quota hierarchy for /var/lib/machines: %m");
174 log_info("Set up default quota hierarchy for /var/lib/machines.");
176 r
= btrfs_subvol_auto_qgroup(path
, 0, true);
178 log_debug_errno(r
, "Failed to set up quota hierarchy for %s, as directory is not on btrfs or not a subvolume. Ignoring.", path
);
182 return log_error_errno(r
, "Failed to set up default quota hierarchy for %s: %m", path
);
184 log_info("Set up default quota hierarchy for %s.", path
);