From f375329965398b29ab15f8c10d12d99d36469c3d Mon Sep 17 00:00:00 2001 From: Sergey Shevchenko Date: Wed, 1 Nov 2023 17:01:20 -0700 Subject: [PATCH] #Centipede Add `WorkDir::ShardedFileInfo::IsShardPath()` query PiperOrigin-RevId: 578685041 --- centipede/workdir.cc | 7 +++++++ centipede/workdir.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/centipede/workdir.cc b/centipede/workdir.cc index 753ac31a..9ed3a2f8 100644 --- a/centipede/workdir.cc +++ b/centipede/workdir.cc @@ -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 diff --git a/centipede/workdir.h b/centipede/workdir.h index c6d0f29d..20271632 100644 --- a/centipede/workdir.h +++ b/centipede/workdir.h @@ -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;