Skip to content

Commit

Permalink
Walk: pass file descriptor to ScanDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Dec 6, 2024
1 parent 0c62924 commit 1a28e0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Walk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void
Walk::Start(FileDescriptor root_fd)
{
WalkDirectoryRef root{WalkDirectoryRef::Adopt{}, *new WalkDirectory(uring, WalkDirectory::RootTag{}, OpenPath(root_fd, ".", O_DIRECTORY))};
ScanDirectory(*root);
ScanDirectory(*root, OpenDirectory(root_fd, "."));
}

inline void
Expand Down Expand Up @@ -137,9 +137,9 @@ IsSpecialFilename(const char *s) noexcept
}

inline void
Walk::ScanDirectory(WalkDirectory &directory)
Walk::ScanDirectory(WalkDirectory &directory, UniqueFileDescriptor &&fd)
{
DirectoryReader r{OpenDirectory(directory.fd, ".")};
DirectoryReader r{std::move(fd)};
while (const char *name = r.Read()) {
if (IsSpecialFilename(name))
continue;
Expand All @@ -159,7 +159,7 @@ try {
*new WalkDirectory(uring, parent, co_await Uring::CoOpen(uring, parent.fd, name.c_str(), O_PATH|O_DIRECTORY, 0)),
};

ScanDirectory(*directory);
ScanDirectory(*directory, OpenDirectory(directory->fd, "."));
} catch (...) {
fmt::print(stderr, "Failed to scan directory: {}\n", std::current_exception());
}
Expand Down
3 changes: 2 additions & 1 deletion src/Walk.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>

class FileDescriptor;
class UniqueFileDescriptor;
namespace Uring { class Queue; }
namespace Co { template <typename T> class Task; }
class WalkHandler;
Expand Down Expand Up @@ -73,7 +74,7 @@ private:
void AddFile(WalkDirectory &parent, std::string &&name,
FileTime atime, uint_least64_t size);

void ScanDirectory(WalkDirectory &directory);
void ScanDirectory(WalkDirectory &directory, UniqueFileDescriptor &&fd);

void OnStatCompletion(StatItem &item) noexcept;
};

0 comments on commit 1a28e0f

Please sign in to comment.