From 81413e6a2f2b171b3a7efa93d18c496da7c14a7e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 5 Mar 2021 21:43:34 -0500 Subject: [PATCH] fix file sizes in the data tab: - bug: if a file had an origin from an archive, the size from the archive was always shown even if the conflict was won by another mod - so, set the file size to NoFileSize when adding a file from the disk, this clears whatever size might be have been set if a previous origin was from an archive - also remove Cached::override(), not sure what the purpose was, looks like it was to prevent fetching the file size again, but it makes no sense and would prevent the file size from being updated ever again even if the winning origin of a file changed --- src/filetreeitem.h | 20 ++++---------------- src/shared/directoryentry.cpp | 12 +++++++++++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/filetreeitem.h b/src/filetreeitem.h index 750e4719f..4c4bea4b3 100644 --- a/src/filetreeitem.h +++ b/src/filetreeitem.h @@ -150,12 +150,12 @@ class FileTreeItem void setFileSize(uint64_t size) { - m_fileSize.override(size); + m_fileSize.set(size); } void setCompressedFileSize(uint64_t compressedSize) { - m_compressedFileSize.override(compressedSize); + m_compressedFileSize.set(compressedSize); } const QString& realPath() const @@ -243,7 +243,6 @@ class FileTreeItem { std::optional value; bool failed = false; - bool overridden = false; bool empty() const { @@ -254,29 +253,18 @@ class FileTreeItem { value = std::move(t); failed = false; - overridden = false; - } - - void override(T t) - { - value = std::move(t); - failed = false; - overridden = true; } void fail() { value = {}; failed = true; - overridden = false; } void reset() { - if (!overridden) { - value = {}; - failed = false; - } + value = {}; + failed = false; } }; diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index badb56362..74b760ab5 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -675,7 +675,17 @@ void DirectoryEntry::onDirectoryEnd(Context* cx, std::wstring_view path) void DirectoryEntry::onFile(Context* cx, std::wstring_view path, FILETIME ft) { elapsed(cx->stats.fileTimes, [&]{ - cx->current.top()->insert(path, cx->origin, ft, L"", -1, cx->stats); + auto f = cx->current.top()->insert(path, cx->origin, ft, L"", -1, cx->stats); + + if (f) { + // the file might already be in the register and it might have come from + // an archive, which sets the file size if it's available (see addFiles() + // just below) + // + // so the file size might be stale here because the file is being + // overridden by another mod, make sure to clear it + f->setFileSize(FileEntry::NoFileSize, FileEntry::NoFileSize); + } }); }