Skip to content

Commit

Permalink
#Centipede Add WorkDir::ShardedFileInfo::IsShardPath() query
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 578685041
  • Loading branch information
ussuri authored and copybara-github committed Nov 2, 2023
1 parent ed5459a commit f375329
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions centipede/workdir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ std::string WorkDir::ShardedFileInfo::AllShardsGlob() const {
return absl::StrCat(prefix_, "*");
}

bool WorkDir::ShardedFileInfo::IsShardPath(std::string_view path) const {
// TODO(ussuri): This is as barebones as it can be right now. Possible
// improvements: 1. Make `path` & `prefix_` absolute before comparing (or in
// ctor for `prefix_`). 2. Add option to require the actual file's existence.
return absl::StartsWith(path, prefix_);
}

//------------------------------------------------------------------------------
// WorkDir

Expand Down
5 changes: 5 additions & 0 deletions centipede/workdir.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class WorkDir {
std::string MyShardPath() const;
// Returns a glob matching all the shard files.
std::string AllShardsGlob() const;
// Returns true if `path` looks like a shard file path from this set.
// Matching is purely lexicographical: the actual file doesn't have to exist
// on disk, but `path` must have the exact `base_dir`/`rel_prefix` prefix,
// including any relative "." and ".." path elements.
bool IsShardPath(std::string_view path) const;

private:
friend class WorkDir;
Expand Down

0 comments on commit f375329

Please sign in to comment.