]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/import/aufs-util.c
tree-wide: remove Emacs lines from all files
[thirdparty/systemd.git] / src / import / aufs-util.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2014 Lennart Poettering
5
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.
10
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.
15
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/>.
18 ***/
19
20 #include <ftw.h>
21
22 #include "aufs-util.h"
23 #include "rm-rf.h"
24 #include "string-util.h"
25 #include "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(fpath, REMOVE_ROOT|REMOVE_PHYSICAL);
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(p, REMOVE_ROOT|REMOVE_PHYSICAL);
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 > 0 ? -errno : -EIO;
71
72 return 0;
73 }