Skip to content

Commit 0e1ec6c

Browse files
committed
reaper/TreeWatch: move code to FindDirectory()
1 parent 1d37581 commit 0e1ec6c

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/reaper/TreeWatch.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ TreeWatch::Add(std::string_view relative_path)
118118
}
119119
}
120120

121-
FileDescriptor
122-
TreeWatch::Find(std::string_view relative_path) const noexcept
121+
const TreeWatch::Directory *
122+
TreeWatch::FindDirectory(std::string_view relative_path) const noexcept
123123
{
124124
assert(root.IsOpen());
125125

@@ -131,12 +131,12 @@ TreeWatch::Find(std::string_view relative_path) const noexcept
131131

132132
const auto i = directory->children.find(name);
133133
if (i == directory->children.end())
134-
return FileDescriptor::Undefined();
134+
return nullptr;
135135

136136
directory = &i->second;
137137
}
138138

139-
return directory->fd;
139+
return directory;
140140
}
141141

142142
TreeWatch::Directory &

src/reaper/TreeWatch.hxx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,21 @@ public:
6969
* #FileDescriptor.
7070
*/
7171
[[gnu::pure]]
72-
FileDescriptor Find(std::string_view relative_path) const noexcept;
72+
FileDescriptor Find(std::string_view relative_path) const noexcept {
73+
const auto *directory = FindDirectory(relative_path);
74+
return directory != nullptr
75+
? FileDescriptor{directory->fd}
76+
: FileDescriptor::Undefined();
77+
}
7378

7479
private:
80+
/**
81+
* Look up a #Directory object. Returns nullptr if the
82+
* specified path is not being watched.
83+
*/
84+
[[gnu::pure]]
85+
const Directory *FindDirectory(std::string_view relative_path) const noexcept;
86+
7587
Directory &MakeChild(Directory &parent, std::string_view name,
7688
bool persist, bool all) noexcept;
7789

0 commit comments

Comments
 (0)