QmlDesigner: Use size for path watcher

The modified time is only saved as milliseconds. That is quite coarse.
So we check if the size changed too.

Change-Id: Ib94382404002b3bcf2d1e45a73b814d8aba1935c
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-04-04 22:39:39 +02:00
parent 6a11b1bc58
commit 88b8d5ea6c
3 changed files with 37 additions and 7 deletions

View File

@@ -116,10 +116,12 @@ public:
ids.push_back(id); ids.push_back(id);
std::ranges::transform(idPath.sourceIds, std::back_inserter(entries), [&](SourceId sourceId) { std::ranges::transform(idPath.sourceIds, std::back_inserter(entries), [&](SourceId sourceId) {
auto fileStatus = m_fileStatusCache.find(sourceId);
return WatcherEntry{id, return WatcherEntry{id,
sourceId.contextId(), sourceId.contextId(),
sourceId, sourceId,
m_fileStatusCache.lastModifiedTime(sourceId)}; fileStatus.lastModified,
fileStatus.size};
}); });
} }
@@ -290,10 +292,11 @@ public:
sourceContextIds, sourceContextIds,
[&](WatcherEntry &entry) { [&](WatcherEntry &entry) {
m_fileStatusCache.update(entry.sourceId); m_fileStatusCache.update(entry.sourceId);
auto currentLastModified = m_fileStatusCache.lastModifiedTime(entry.sourceId); auto fileStatus = m_fileStatusCache.find(entry.sourceId);
if (entry.lastModified < currentLastModified) { if (entry.lastModified < fileStatus.lastModified || entry.size != fileStatus.size) {
foundEntries.push_back(entry); foundEntries.push_back(entry);
entry.lastModified = currentLastModified; entry.lastModified = fileStatus.lastModified;
entry.size = fileStatus.size;
} }
}, },
{}, {},

View File

@@ -103,6 +103,7 @@ public:
SourceContextId sourceContextId; SourceContextId sourceContextId;
SourceId sourceId; SourceId sourceId;
long long lastModified = -1; long long lastModified = -1;
long long size = -1;
friend bool operator==(WatcherEntry first, WatcherEntry second) friend bool operator==(WatcherEntry first, WatcherEntry second)
{ {

View File

@@ -378,13 +378,12 @@ TEST_F(ProjectStoragePathWatcher, two_notify_file_changes)
mockQFileSytemWatcher.directoryChanged(sourceContextPath2); mockQFileSytemWatcher.directoryChanged(sourceContextPath2);
} }
TEST_F(ProjectStoragePathWatcher, notify_for_path_changes) TEST_F(ProjectStoragePathWatcher, notify_for_path_changes_if_modified_time_changes)
{ {
watcher.updateIdPaths({{projectChunkId1, {sourceIds[0], sourceIds[1], sourceIds[2]}}, watcher.updateIdPaths({{projectChunkId1, {sourceIds[0], sourceIds[1], sourceIds[2]}},
{projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}}); {projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}});
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0]))) ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0])))
.WillByDefault(Return(FileStatus{sourceIds[0], 1, 2})); .WillByDefault(Return(FileStatus{sourceIds[0], 1, 2}));
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3]))) ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3])))
.WillByDefault(Return(FileStatus{sourceIds[3], 1, 2})); .WillByDefault(Return(FileStatus{sourceIds[3], 1, 2}));
@@ -393,6 +392,34 @@ TEST_F(ProjectStoragePathWatcher, notify_for_path_changes)
mockQFileSytemWatcher.directoryChanged(sourceContextPath); mockQFileSytemWatcher.directoryChanged(sourceContextPath);
} }
TEST_F(ProjectStoragePathWatcher, notify_for_path_changes_if_size_get_bigger)
{
watcher.updateIdPaths({{projectChunkId1, {sourceIds[0], sourceIds[1], sourceIds[2]}},
{projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}});
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0])))
.WillByDefault(Return(FileStatus{sourceIds[0], 2, 1}));
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3])))
.WillByDefault(Return(FileStatus{sourceIds[3], 2, 1}));
EXPECT_CALL(notifier, pathsChanged(ElementsAre(sourceIds[0])));
mockQFileSytemWatcher.directoryChanged(sourceContextPath);
}
TEST_F(ProjectStoragePathWatcher, notify_for_path_changes_if_size_get_smaller)
{
watcher.updateIdPaths({{projectChunkId1, {sourceIds[0], sourceIds[1], sourceIds[2]}},
{projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}});
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0])))
.WillByDefault(Return(FileStatus{sourceIds[0], 0, 1}));
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3])))
.WillByDefault(Return(FileStatus{sourceIds[3], 0, 1}));
EXPECT_CALL(notifier, pathsChanged(ElementsAre(sourceIds[0])));
mockQFileSytemWatcher.directoryChanged(sourceContextPath);
}
TEST_F(ProjectStoragePathWatcher, no_notify_for_unwatched_path_changes) TEST_F(ProjectStoragePathWatcher, no_notify_for_unwatched_path_changes)
{ {
watcher.updateIdPaths({{projectChunkId1, {sourceIds[3]}}, {projectChunkId2, {sourceIds[3]}}}); watcher.updateIdPaths({{projectChunkId1, {sourceIds[3]}}, {projectChunkId2, {sourceIds[3]}}});
@@ -442,7 +469,6 @@ TEST_F(ProjectStoragePathWatcher, trigger_manual_notify_for_path_changes)
{projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}}); {projectChunkId2, {sourceIds[0], sourceIds[1], sourceIds[3]}}});
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0]))) ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[0])))
.WillByDefault(Return(FileStatus{sourceIds[0], 1, 2})); .WillByDefault(Return(FileStatus{sourceIds[0], 1, 2}));
ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3]))) ON_CALL(mockFileSystem, fileStatus(Eq(sourceIds[3])))
.WillByDefault(Return(FileStatus{sourceIds[3], 1, 2})); .WillByDefault(Return(FileStatus{sourceIds[3], 1, 2}));