Skip to content

Commit c5922e6

Browse files
OSS-Fuzz Teamcopybara-github
authored andcommitted
Skip non existing file
Indexer-PiperOrigin-RevId: 840240920
1 parent 21d3bfa commit c5922e6

File tree

5 files changed

+26
-56
lines changed

5 files changed

+26
-56
lines changed

infra/indexer/index/file_copier.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ void PreparePath(std::string& path) {
4242
FileCopier::FileCopier(absl::string_view base_path,
4343
absl::string_view index_path,
4444
const std::vector<std::string>& extra_paths,
45-
Behavior behavior)
45+
Behavior behavior, bool skip_missing_files)
4646
: base_path_(base_path),
4747
extra_paths_(extra_paths),
4848
index_path_(index_path),
49-
behavior_(behavior) {
49+
behavior_(behavior),
50+
skip_missing_files_(skip_missing_files) {
5051
if (behavior_ == Behavior::kNoOp) {
5152
return;
5253
}
@@ -102,10 +103,17 @@ void FileCopier::CopyIndexedFiles() {
102103
dst_path = std::filesystem::path(index_path_) / "relative" / indexed_path;
103104
}
104105

105-
DLOG(INFO) << "\nFrom: " << src_path << "\n To: " << dst_path << "\n";
106+
if (!std::filesystem::exists(src_path)) {
107+
if (!skip_missing_files_) {
108+
LOG(QFATAL) << "Source file " << src_path
109+
<< " does not exist and skip_missing_files is false.";
110+
} else {
111+
LOG(WARNING) << "Skipping non-existent source file: " << src_path;
112+
continue;
113+
}
114+
}
106115

107-
QCHECK(std::filesystem::exists(src_path))
108-
<< "Source file does not exist: " << src_path;
116+
DLOG(INFO) << "\nFrom: " << src_path << "\n To: " << dst_path << "\n";
109117

110118
std::error_code error_code;
111119
// The destination directory may already exist, but report other errors.

infra/indexer/index/file_copier.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ namespace indexer {
3232
// all InMemoryIndexes for the current project.
3333
class FileCopier {
3434
public:
35-
enum class Behavior { kNoOp, kFailOnExistingFiles, kOverwriteExistingFiles };
35+
enum class Behavior {
36+
kNoOp,
37+
kFailOnExistingFiles,
38+
kOverwriteExistingFiles,
39+
};
3640

3741
FileCopier(absl::string_view base_path, absl::string_view index_path,
3842
const std::vector<std::string>& extra_paths,
39-
Behavior behavior = Behavior::kFailOnExistingFiles);
43+
Behavior behavior = Behavior::kFailOnExistingFiles,
44+
bool skip_missing_files = false);
4045
FileCopier(const FileCopier&) = delete;
4146

4247
// Takes an absolute path. Rewrites this path into the representation it will
@@ -55,6 +60,7 @@ class FileCopier {
5560
std::vector<std::string> extra_paths_;
5661
const std::filesystem::path index_path_;
5762
const Behavior behavior_;
63+
const bool skip_missing_files_;
5864

5965
absl::Mutex mutex_;
6066
absl::flat_hash_set<std::string> indexed_files_ ABSL_GUARDED_BY(mutex_);

infra/indexer/main.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ ABSL_FLAG(bool, delta, false,
6262
ABSL_FLAG(std::string, database_only, "",
6363
"Do not copy source files, only build the index database at the given"
6464
" location (--index_dir is not effective in that case)");
65+
ABSL_FLAG(bool, skip_missing_files, false,
66+
"If set to true, missing source files will be skipped with a warning."
67+
" If false, the indexer will error out on missing files.");
6568

6669
static constexpr char kIndexDbName[] = "db.sqlite";
6770
static constexpr char kDeltaDbName[] = "delta.sqlite";
@@ -122,7 +125,8 @@ int main(int argc, char** argv) {
122125
}
123126
}
124127

125-
FileCopier file_copier(source_dir, index_dir, extra_dirs, behavior);
128+
FileCopier file_copier(source_dir, index_dir, extra_dirs, behavior,
129+
absl::GetFlag(FLAGS_skip_missing_files));
126130

127131
std::unique_ptr<MergeQueue> merge_queue = MergeQueue::Create(
128132
absl::GetFlag(FLAGS_merge_queues), absl::GetFlag(FLAGS_merge_queue_size));

infra/indexer/ubuntu-20-04.Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

infra/indexer/ubuntu-24-04.Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)