Skip to content

Commit ba82ed9

Browse files
committed
chore(file_scanner): better error checking for file_start_hash_
1 parent 96d526f commit ba82ed9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/dwarfs/file_scanner.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,15 @@ void file_scanner_<LoggerPolicy>::finalize(uint32_t& inode_num) {
206206
if (auto it = by_hash_.find(p->hash()); it != by_hash_.end()) {
207207
return it->second;
208208
}
209-
auto it = file_start_hash_.find(p);
210-
uint64_t hash = it != file_start_hash_.end() ? it->second : 0;
211-
return unique_size_.at({p->size(), hash});
209+
auto const size = p->size();
210+
uint64_t hash{0};
211+
if (size >= kLargeFileThreshold) [[unlikely]] {
212+
auto it = file_start_hash_.find(p);
213+
DWARFS_CHECK(it != file_start_hash_.end(),
214+
"internal error: missing start hash for large file");
215+
hash = it->second;
216+
}
217+
return unique_size_.at({size, hash});
212218
});
213219
finalize_files<true>(unique_size_, inode_num, obj_num);
214220
finalize_files(by_raw_inode_, inode_num, obj_num);

0 commit comments

Comments
 (0)