]>
Commit | Line | Data |
---|---|---|
72648326 LP |
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 | ||
c6878637 | 24 | #include "rm-rf.h" |
07630cea LP |
25 | #include "string-util.h" |
26 | #include "util.h" | |
72648326 LP |
27 | #include "aufs-util.h" |
28 | ||
29 | static int nftw_cb( | |
30 | const char *fpath, | |
31 | const struct stat *sb, | |
32 | int flag, | |
33 | struct FTW *ftwbuf) { | |
34 | ||
35 | const char *fn, *original; | |
36 | char *p; | |
37 | int r; | |
38 | ||
39 | fn = fpath + ftwbuf->base; | |
40 | ||
41 | /* We remove all whiteout files, and all whiteouts */ | |
42 | ||
43 | original = startswith(fn, ".wh."); | |
44 | if (!original) | |
45 | return FTW_CONTINUE; | |
46 | ||
47 | log_debug("Removing whiteout indicator %s.", fpath); | |
c6878637 | 48 | r = rm_rf(fpath, REMOVE_ROOT|REMOVE_PHYSICAL); |
72648326 LP |
49 | if (r < 0) |
50 | return FTW_STOP; | |
51 | ||
52 | if (!startswith(fn, ".wh..wh.")) { | |
53 | ||
54 | p = alloca(ftwbuf->base + strlen(original)); | |
55 | strcpy(mempcpy(p, fpath, ftwbuf->base), original); | |
56 | ||
57 | log_debug("Removing deleted file %s.", p); | |
c6878637 | 58 | r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL); |
72648326 LP |
59 | if (r < 0) |
60 | return FTW_STOP; | |
61 | } | |
62 | ||
63 | return FTW_CONTINUE; | |
64 | } | |
65 | ||
66 | int aufs_resolve(const char *path) { | |
67 | int r; | |
68 | ||
69 | errno = 0; | |
70 | r = nftw(path, nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); | |
71 | if (r == FTW_STOP) | |
72 | return errno ? -errno : -EIO; | |
73 | ||
74 | return 0; | |
75 | } |