From c11f2ba978e398e54995b96d3cc291b81465d008 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 18 Oct 2024 21:36:21 -0400 Subject: [PATCH] Fix case where copying a subset doesn't update --- src/cb/src/externalclipboards.cpp | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/cb/src/externalclipboards.cpp b/src/cb/src/externalclipboards.cpp index 84a474082..2d04b166b 100644 --- a/src/cb/src/externalclipboards.cpp +++ b/src/cb/src/externalclipboards.cpp @@ -136,19 +136,31 @@ void convertFromGUIClipboard(const ClipboardPaths& clipboard) { // Only clear the temp directory if all files in the clipboard are outside the temp directory // This avoids the situation where we delete the very files we're trying to copy - auto filesHaveChanged = std::all_of(paths.begin(), paths.end(), [](auto& path) { - auto filename = path.filename().empty() ? path.parent_path().filename() : path.filename(); - // check if the filename of the provided path does not exist in the temp directory - if (!fs::exists(::path.data / filename)) return true; - - // check if the file sizes are different if it's not a directory - if (!fs::is_directory(path) && fs::file_size(path) != fs::file_size(::path.data / filename)) return true; - - // check if the file contents are different if it's not a directory - if (!fs::is_directory(path) && fileContents(path).value() != fileContents(::path.data / filename)) return true; - - return false; - }); + auto filesHaveChanged = std::all_of( + paths.begin(), + paths.end(), + [](auto& path) { + auto filename = path.filename().empty() ? path.parent_path().filename() : path.filename(); + // check if the filename of the provided path does not exist in the temp directory + if (!fs::exists(::path.data / filename)) return true; + + // check if the file sizes are different if it's not a directory + if (!fs::is_directory(path) && fs::file_size(path) != fs::file_size(::path.data / filename)) return true; + + // check if the file contents are different if it's not a directory + if (!fs::is_directory(path) && fileContents(path).value() != fileContents(::path.data / filename)) return true; + + return false; + } + ) + || std::any_of( + fs::directory_iterator(::path.data), + fs::directory_iterator {}, + [&paths](auto& entry) { // Check if at there is at least one file already in the temp directory that is not in the clipboard + auto filename = entry.path().filename(); + return std::none_of(paths.begin(), paths.end(), [&filename](auto& path) { return path.filename() == filename; }); + } + ); auto eligibleForCopying = std::all_of(paths.begin(), paths.end(), [](auto& path) { if (!fs::exists(path)) return false;