|
a/src/utils/fstreewalk.cpp |
|
b/src/utils/fstreewalk.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.11 2007-02-02 10:12:58 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: fstreewalk.cpp,v 1.12 2007-07-12 10:53:07 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
87 |
data->skippedNames = patterns;
|
87 |
data->skippedNames = patterns;
|
88 |
data->skippedNames.sort();
|
88 |
data->skippedNames.sort();
|
89 |
data->skippedNames.unique();
|
89 |
data->skippedNames.unique();
|
90 |
return true;
|
90 |
return true;
|
91 |
}
|
91 |
}
|
|
|
92 |
bool FsTreeWalker::inSkippedNames(const string& name)
|
|
|
93 |
{
|
|
|
94 |
list<string>::const_iterator it;
|
|
|
95 |
for (it = data->skippedNames.begin();
|
|
|
96 |
it != data->skippedNames.end(); it++) {
|
|
|
97 |
if (fnmatch(it->c_str(), name.c_str(), 0) == 0) {
|
|
|
98 |
return true;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return false;
|
|
|
102 |
}
|
92 |
|
103 |
|
93 |
bool FsTreeWalker::addSkippedPath(const string& ipath)
|
104 |
bool FsTreeWalker::addSkippedPath(const string& ipath)
|
94 |
{
|
105 |
{
|
95 |
string path = path_canon(ipath);
|
106 |
string path = path_canon(ipath);
|
96 |
if (find(data->skippedPaths.begin(),
|
107 |
if (find(data->skippedPaths.begin(),
|
|
... |
|
... |
105 |
it != data->skippedPaths.end(); it++)
|
116 |
it != data->skippedPaths.end(); it++)
|
106 |
*it = path_canon(*it);
|
117 |
*it = path_canon(*it);
|
107 |
data->skippedPaths.sort();
|
118 |
data->skippedPaths.sort();
|
108 |
data->skippedPaths.unique();
|
119 |
data->skippedPaths.unique();
|
109 |
return true;
|
120 |
return true;
|
|
|
121 |
}
|
|
|
122 |
bool FsTreeWalker::inSkippedPaths(const string& path)
|
|
|
123 |
{
|
|
|
124 |
list<string>::const_iterator it;
|
|
|
125 |
for (it = data->skippedPaths.begin();
|
|
|
126 |
it != data->skippedPaths.end(); it++) {
|
|
|
127 |
if (fnmatch(it->c_str(), path.c_str(), FNM_PATHNAME) == 0)
|
|
|
128 |
return true;
|
|
|
129 |
}
|
|
|
130 |
return false;
|
110 |
}
|
131 |
}
|
111 |
|
132 |
|
112 |
FsTreeWalker::Status FsTreeWalker::walk(const string &top,
|
133 |
FsTreeWalker::Status FsTreeWalker::walk(const string &top,
|
113 |
FsTreeWalkerCB& cb)
|
134 |
FsTreeWalkerCB& cb)
|
114 |
{
|
135 |
{
|
|
... |
|
... |
154 |
}
|
175 |
}
|
155 |
}
|
176 |
}
|
156 |
|
177 |
|
157 |
struct dirent *ent;
|
178 |
struct dirent *ent;
|
158 |
while ((ent = readdir(d)) != 0) {
|
179 |
while ((ent = readdir(d)) != 0) {
|
159 |
// We do process hidden files for now, only skip . and ..
|
180 |
// Skip . and ..
|
160 |
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
181 |
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
161 |
continue;
|
182 |
continue;
|
162 |
|
183 |
|
|
|
184 |
// Skipped file names match ?
|
163 |
if (!data->skippedNames.empty()) {
|
185 |
if (!data->skippedNames.empty()) {
|
164 |
list<string>::const_iterator it;
|
186 |
if (inSkippedNames(ent->d_name))
|
165 |
for (it = data->skippedNames.begin();
|
|
|
166 |
it != data->skippedNames.end(); it++) {
|
|
|
167 |
if (fnmatch(it->c_str(), ent->d_name, 0) == 0) {
|
|
|
168 |
//fprintf(stderr,
|
|
|
169 |
//"Skipping [%s] because of pattern match\n", ent->d_name);
|
|
|
170 |
goto skip;
|
187 |
goto skip;
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
}
|
188 |
}
|
174 |
|
189 |
|
175 |
{
|
190 |
{
|
176 |
string fn = path_cat(top, ent->d_name);
|
191 |
string fn = path_cat(top, ent->d_name);
|
177 |
|
192 |
|
|
... |
|
... |
181 |
if (statret == -1) {
|
196 |
if (statret == -1) {
|
182 |
data->logsyserr("stat", fn);
|
197 |
data->logsyserr("stat", fn);
|
183 |
continue;
|
198 |
continue;
|
184 |
}
|
199 |
}
|
185 |
if (!data->skippedPaths.empty()) {
|
200 |
if (!data->skippedPaths.empty()) {
|
186 |
list<string>::const_iterator it;
|
201 |
if (inSkippedPaths(fn))
|
187 |
for (it = data->skippedPaths.begin();
|
|
|
188 |
it != data->skippedPaths.end(); it++) {
|
|
|
189 |
if (fnmatch(it->c_str(), fn.c_str(), FNM_PATHNAME) == 0)
|
|
|
190 |
goto skip;
|
202 |
goto skip;
|
191 |
}
|
|
|
192 |
}
|
203 |
}
|
193 |
|
204 |
|
194 |
if (S_ISDIR(st.st_mode)) {
|
205 |
if (S_ISDIR(st.st_mode)) {
|
195 |
if (data->options & FtwNoRecurse) {
|
206 |
if (data->options & FtwNoRecurse) {
|
196 |
status = cb.processone(fn, &st, FtwDirEnter);
|
207 |
status = cb.processone(fn, &st, FtwDirEnter);
|