Skip to content

Commit 41849db

Browse files
mkieselmkiesel
andauthored
avoid touching packfiles on startup (#1793)
ArchiveFile::start_up() truncates packfiles unconditionally, causing unneeded filesystem writes (mtime) and complicating auditing on file level. Co-authored-by: mkiesel <[email protected]>
1 parent a7c0010 commit 41849db

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

validator/db/package.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ Package::Package(td::FileFd fd) : fd_(std::move(fd)) {
4848
}
4949

5050
td::Status Package::truncate(td::uint64 size) {
51-
TRY_STATUS(fd_.seek(size + header_size()));
52-
return fd_.truncate_to_current_position(size + header_size());
51+
auto target_size = size + header_size();
52+
TRY_RESULT(current_size, fd_.get_size());
53+
54+
// Only truncate if the size actually differs to avoid updating mtime unnecessarily
55+
if (current_size != target_size) {
56+
TRY_STATUS(fd_.seek(target_size));
57+
return fd_.truncate_to_current_position(target_size);
58+
}
59+
60+
return td::Status::OK();
5361
}
5462

5563
td::uint64 Package::append(std::string filename, td::Slice data, bool sync) {

0 commit comments

Comments
 (0)