Switch to unified view

a/src/utils/wipedir.cpp b/src/utils/wipedir.cpp
...
...
27
#include <dirent.h>
27
#include <dirent.h>
28
28
29
#include <cstring>
29
#include <cstring>
30
#include <string>
30
#include <string>
31
31
32
#include "debuglog.h"
32
#include "log.h"
33
#include "pathut.h"
33
#include "pathut.h"
34
#include "wipedir.h"
34
#include "wipedir.h"
35
35
36
using namespace std;
36
using namespace std;
37
37
...
...
41
    int statret;
41
    int statret;
42
    int ret = -1;
42
    int ret = -1;
43
43
44
    statret = lstat(dir.c_str(), &st);
44
    statret = lstat(dir.c_str(), &st);
45
    if (statret == -1) {
45
    if (statret == -1) {
46
  LOGERR(("wipedir: cant stat %s, errno %d\n", dir.c_str(), errno));
46
  LOGERR("wipedir: cant stat "  << (dir) << ", errno "  << (errno) << "\n" );
47
    return -1;
47
    return -1;
48
    }
48
    }
49
    if (!S_ISDIR(st.st_mode)) {
49
    if (!S_ISDIR(st.st_mode)) {
50
  LOGERR(("wipedir: %s not a directory\n", dir.c_str()));
50
  LOGERR("wipedir: "  << (dir) << " not a directory\n" );
51
    return -1;
51
    return -1;
52
    }
52
    }
53
53
54
    if (access(dir.c_str(), R_OK|W_OK|X_OK) < 0) {
54
    if (access(dir.c_str(), R_OK|W_OK|X_OK) < 0) {
55
  LOGERR(("wipedir: no write access to %s\n", dir.c_str()));
55
  LOGERR("wipedir: no write access to "  << (dir) << "\n" );
56
    return -1;
56
    return -1;
57
    }
57
    }
58
58
59
    DIR *d = opendir(dir.c_str());
59
    DIR *d = opendir(dir.c_str());
60
    if (d == 0) {
60
    if (d == 0) {
61
  LOGERR(("wipedir: cant opendir %s, errno %d\n", dir.c_str(), errno));
61
  LOGERR("wipedir: cant opendir "  << (dir) << ", errno "  << (errno) << "\n" );
62
    return -1;
62
    return -1;
63
    }
63
    }
64
    int remaining = 0;
64
    int remaining = 0;
65
    struct dirent *ent;
65
    struct dirent *ent;
66
    while ((ent = readdir(d)) != 0) {
66
    while ((ent = readdir(d)) != 0) {
...
...
70
    string fn = path_cat(dir, ent->d_name);
70
    string fn = path_cat(dir, ent->d_name);
71
71
72
    struct stat st;
72
    struct stat st;
73
    int statret = lstat(fn.c_str(), &st);
73
    int statret = lstat(fn.c_str(), &st);
74
    if (statret == -1) {
74
    if (statret == -1) {
75
      LOGERR(("wipedir: cant stat %s, errno %d\n", fn.c_str(), errno));
75
      LOGERR("wipedir: cant stat "  << (fn) << ", errno "  << (errno) << "\n" );
76
        goto out;
76
        goto out;
77
    }
77
    }
78
    if (S_ISDIR(st.st_mode)) {
78
    if (S_ISDIR(st.st_mode)) {
79
        if (recurse) {
79
        if (recurse) {
80
        int rr = wipedir(fn, true, true);
80
        int rr = wipedir(fn, true, true);
...
...
85
        } else {
85
        } else {
86
        remaining++;
86
        remaining++;
87
        }
87
        }
88
    } else {
88
    } else {
89
        if (unlink(fn.c_str()) < 0) {
89
        if (unlink(fn.c_str()) < 0) {
90
      LOGERR(("wipedir: cant unlink %s, errno %d\n", 
90
      LOGERR("wipedir: cant unlink "  << (fn) << ", errno "  << (errno) << "\n" );
91
          fn.c_str(), errno));
92
        goto out;
91
        goto out;
93
        }
92
        }
94
    }
93
    }
95
    }
94
    }
96
95
97
    ret = remaining;
96
    ret = remaining;
98
    if (selfalso && ret == 0) {
97
    if (selfalso && ret == 0) {
99
    if (rmdir(dir.c_str()) < 0) {
98
    if (rmdir(dir.c_str()) < 0) {
100
      LOGERR(("wipedir: rmdir(%s) failed, errno %d\n",
99
      LOGERR("wipedir: rmdir("  << (dir) << ") failed, errno "  << (errno) << "\n" );
101
          dir.c_str(), errno));
102
        ret = -1;
100
        ret = -1;
103
    }
101
    }
104
    }
102
    }
105
103
106
 out:
104
 out:
...
...
165
    printf("wipedir returned %d\n", cnt);
163
    printf("wipedir returned %d\n", cnt);
166
    exit(0);
164
    exit(0);
167
}
165
}
168
166
169
#endif
167
#endif
168