Browse Source

FileList: bug fix when importing the same note file in the same folder

Le Tan 7 năm trước cách đây
mục cha
commit
feea50d888
2 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 4 1
      src/vfile.cpp
  2. 10 0
      src/vfilelist.cpp

+ 4 - 1
src/vfile.cpp

@@ -44,7 +44,10 @@ bool VFile::open()
     Q_ASSERT(m_content.isEmpty());
 
     QString filePath = fetchPath();
-    Q_ASSERT(QFileInfo::exists(filePath));
+    if (!QFileInfo::exists(filePath)) {
+        return false;
+    }
+
     m_content = VUtils::readFileFromDisk(filePath);
     m_lastModified = QFileInfo(filePath).lastModified();
     m_opened = true;

+ 10 - 0
src/vfilelist.cpp

@@ -771,6 +771,16 @@ bool VFileList::importFiles(const QStringList &p_files, QString *p_errMsg)
 
         bool copyNeeded = true;
         if (VUtils::equalPath(dirPath, fi.absolutePath())) {
+            // Check if it is already a note.
+            if (m_directory->findFile(name, false)) {
+                VUtils::addErrMsg(p_errMsg, tr("Skip importing file %1. "
+                                               "A note with the same name (case-insensitive) "
+                                               "in the same directory already exists.")
+                                              .arg(file));
+                ret = false;
+                continue;
+            }
+
             qDebug() << "skip cpoy file" << file << "locates in" << dirPath;
             copyNeeded = false;
         }