chiark / gitweb /
import: drop all capabilities when invoking tar
[elogind.git] / src / import / aufs-util.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2014 Lennart Poettering
7
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.
12
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.
17
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/>.
20 ***/
21
22 #include <ftw.h>
23
24 #include "util.h"
25 #include "aufs-util.h"
26
27 static int nftw_cb(
28                 const char *fpath,
29                 const struct stat *sb,
30                 int flag,
31                 struct FTW *ftwbuf) {
32
33         const char *fn, *original;
34         char *p;
35         int r;
36
37         fn = fpath + ftwbuf->base;
38
39         /* We remove all whiteout files, and all whiteouts */
40
41         original = startswith(fn, ".wh.");
42         if (!original)
43                 return FTW_CONTINUE;
44
45         log_debug("Removing whiteout indicator %s.", fpath);
46         r = rm_rf_dangerous(fpath, false, true, false);
47         if (r < 0)
48                 return FTW_STOP;
49
50         if (!startswith(fn, ".wh..wh.")) {
51
52                 p = alloca(ftwbuf->base + strlen(original));
53                 strcpy(mempcpy(p, fpath, ftwbuf->base), original);
54
55                 log_debug("Removing deleted file %s.", p);
56                 r = rm_rf_dangerous(p, false, true, false);
57                 if (r < 0)
58                         return FTW_STOP;
59         }
60
61         return FTW_CONTINUE;
62 }
63
64 int aufs_resolve(const char *path) {
65         int r;
66
67         errno = 0;
68         r = nftw(path, nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL);
69         if (r == FTW_STOP)
70                 return errno ? -errno : -EIO;
71
72         return 0;
73 }