View Single Post
Old 04-07-2024, 11:16 AM   #23
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,727
Karma: 5444398
Join Date: Nov 2009
Device: many
Okay, here is an updated version that tries to be as fast (accessing file info on filesystems can be quite slow) as possible, but still work on Linux, MacOS, and Windows.

Code:
diff --git a/src/MainUI/OPFModel.cpp b/src/MainUI/OPFModel.cpp
index 3e9e7715f..59988d6a0 100644
--- a/src/MainUI/OPFModel.cpp
+++ b/src/MainUI/OPFModel.cpp
@@ -765,10 +765,21 @@ bool OPFModel::FilenameIsValid(const QString &old_bookpath, const QString &new_f
     QString sdir = Utility::startingDir(old_bookpath);
     QString proposed_bookpath = sdir.isEmpty() ? new_filename : sdir + "/" + new_filename;
     const QStringList existing_bookpaths = m_Book->GetFolderKeeper()->GetAllBookPaths();
+    // Using QFileInfo is slow so pretest with a much faster method before using it
     if (existing_bookpaths.contains(proposed_bookpath, Qt::CaseInsensitive)) {
-        Utility::DisplayStdErrorDialog(
-            tr("The filename \"%1\" is already in use.\n").arg(new_filename));
-        return false;
+        // potential issue on filesystems that are case insensitive
+        QString FullPathToMainFolder = m_Book->GetFolderKeeper()->GetFullPathToMainFolder();
+        QString orig_full_path = FullPathToMainFolder + "/" + old_bookpath;
+        QString proposed_full_path = FullPathToMainFolder + "/" + proposed_bookpath;
+        if (QFileInfo::exists(proposed_full_path)) {
+            // return false if orig_full_path and proposed_full_path are different files
+            // but allow through case only variationss from case insensitive filesystems
+            if (QFileInfo(orig_full_path) != QFileInfo(proposed_full_path)) {
+                Utility::DisplayStdErrorDialog(
+                    tr("The filename \"%1\" is already in use.\n").arg(new_filename));
+                return false;
+            }
+        }
     }
     return true;
 }

Please someone give this new version a try on Linux and Windows. It works on MacOS.

Thanks
KevinH is offline   Reply With Quote