{
boost::this_thread::interruption_point();
- const vector<string> entries1 = dir1.entries();
+ vector<string> entries1 = dir1.entries();
+ sort(entries1.begin(), entries1.end());
vector<string>::const_iterator first1 = entries1.begin();
vector<string>::const_iterator last1 = entries1.end();
- const vector<string> entries2 = dir2.entries();
+ vector<string> entries2 = dir2.entries();
+ sort(entries2.begin(), entries2.end());
vector<string>::const_iterator first2 = entries2.begin();
vector<string>::const_iterator last2 = entries2.end();
throw IOErrorException();
}
- struct stat stat;
- fstat(dirfd, &stat);
- if (!S_ISDIR(stat.st_mode))
+ struct stat buf;
+ fstat(dirfd, &buf);
+ if (!S_ISDIR(buf.st_mode))
{
y2err("not a directory path:" << base_path);
throw IOErrorException();
throw IOErrorException();
}
- struct stat stat;
- fstat(dirfd, &stat);
- if (!S_ISDIR(stat.st_mode))
+ struct stat buf;
+ fstat(dirfd, &buf);
+ if (!S_ISDIR(buf.st_mode))
{
y2err("not a directory path:" << dir.fullname(name));
throw IOErrorException();
vector<string>
- SDir::entries(std::function<bool(unsigned char, const char* name)> pred) const
+ SDir::entries(entries_pred_t pred) const
{
int fd = dup(dirfd);
if (fd == -1)
struct dirent* ep = (struct dirent*) malloc(len);
struct dirent* epp;
+ rewinddir(dp);
while (readdir_r(dp, ep, &epp) == 0 && epp != NULL)
{
if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 &&
closedir(dp);
- sort(ret.begin(), ret.end());
+ return ret;
+ }
+
+
+ vector<string>
+ SDir::entries_recursive() const
+ {
+ return entries_recursive(all_entries);
+ }
+
+
+ vector<string>
+ SDir::entries_recursive(entries_pred_t pred) const
+ {
+ vector<string> ret;
+
+ vector<string> a = entries(pred);
+ for (vector<string>::const_iterator it1 = a.begin(); it1 != a.end(); ++it1)
+ {
+ ret.push_back(*it1);
+
+ struct stat buf;
+ stat(*it1, &buf, AT_SYMLINK_NOFOLLOW);
+ if (S_ISDIR(buf.st_mode))
+ {
+ vector<string> b = SDir(*this, *it1).entries_recursive();
+ for (vector<string>::const_iterator it2 = b.begin(); it2 != b.end(); ++it2)
+ {
+ ret.push_back(*it1 + "/" + *it2);
+ }
+ }
+ }
return ret;
}
string fullname(bool with_base_path = true) const;
string fullname(const string& name, bool with_base_path = true) const;
+ // Type is not supported by all file system types, see readdir(3).
+ typedef std::function<bool(unsigned char type, const char* name)> entries_pred_t;
+
+ // The order of the result of the entries functions is undefined.
vector<string> entries() const;
- vector<string> entries(std::function<bool(unsigned char type, const char* name)> pred) const;
+ vector<string> entries(entries_pred_t pred) const;
+ vector<string> entries_recursive() const;
+ vector<string> entries_recursive(entries_pred_t pred) const;
int stat(struct stat* buf) const;