@@ -117,7 +117,6 @@ DependencyScanningFilesystemSharedCache::getOutOfDateEntries(
117117 std::lock_guard<std::mutex> LockGuard (Shard.CacheLock );
118118 for (const auto &[Path, CachedPair] : Shard.CacheByFilename ) {
119119 const CachedFileSystemEntry *Entry = CachedPair.first ;
120-
121120 llvm::ErrorOr<llvm::vfs::Status> Status = UnderlyingFS.status (Path);
122121 if (Status) {
123122 if (Entry->getError ()) {
@@ -128,12 +127,22 @@ DependencyScanningFilesystemSharedCache::getOutOfDateEntries(
128127 InvalidDiagInfo.emplace_back (Path.data ());
129128 } else {
130129 llvm::vfs::Status CachedStatus = Entry->getStatus ();
131- uint64_t CachedSize = CachedStatus.getSize ();
132- uint64_t ActualSize = Status->getSize ();
133- if (CachedSize != ActualSize) {
134- // This is the case where the cached file has a different size
135- // from the actual file that comes from the underlying FS.
136- InvalidDiagInfo.emplace_back (Path.data (), CachedSize, ActualSize);
130+ if (Status->getType () == llvm::sys::fs::file_type::regular_file &&
131+ Status->getType () == CachedStatus.getType ()) {
132+ // We only check regular files. Directory files sizes could change
133+ // due to content changes, and reporting directory size changes can
134+ // lead to false positives.
135+ // TODO: At the moment, we do not detect symlinks to files whose
136+ // size may change. We need to decide if we want to detect cached
137+ // symlink size changes. We can also expand this to detect file
138+ // type changes.
139+ uint64_t CachedSize = CachedStatus.getSize ();
140+ uint64_t ActualSize = Status->getSize ();
141+ if (CachedSize != ActualSize) {
142+ // This is the case where the cached file has a different size
143+ // from the actual file that comes from the underlying FS.
144+ InvalidDiagInfo.emplace_back (Path.data (), CachedSize, ActualSize);
145+ }
137146 }
138147 }
139148 }
0 commit comments