diff --git a/src/adaptors/UBImportDocumentSetAdaptor.cpp b/src/adaptors/UBImportDocumentSetAdaptor.cpp index cdc9250b..8d74bf93 100644 --- a/src/adaptors/UBImportDocumentSetAdaptor.cpp +++ b/src/adaptors/UBImportDocumentSetAdaptor.cpp @@ -94,11 +94,17 @@ QFileInfoList UBImportDocumentSetAdaptor::importData(const QString &zipFile, con foreach(QFileInfo readDir, tDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden , QDir::Name)) { QString newFileName = readDir.fileName(); - if (QFileInfo(destination + "/" + readDir.fileName()).exists()) { - newFileName = QFileInfo(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(tmpDir)).fileName(); + if (QFileInfo(destination + "/" + newFileName).exists()) + { + //if the generateUniqueDocumentPath is called twice in the same millisecond, the destination files are overwritten + do + { + newFileName = QFileInfo(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(tmpDir)).fileName(); + } while (QFileInfo(destination + "/" + newFileName).exists()); } + QString newFilePath = destination + "/" + newFileName; - if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath)) { + if (UBFileSystemUtils::copy(readDir.absoluteFilePath(), newFilePath, true)) { result.append(newFilePath); } } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index b3b913a2..99c5999f 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -780,6 +780,7 @@ void UBBoardController::deleteScene(int nIndex) scIndexes << nIndex; deletePages(scIndexes); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); + selectedDocument()->setMetaData(UBSettings::documentPageCount, QString::number(pageCount()-1)); if (nIndex >= pageCount()) nIndex = pageCount()-1; diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 03d676fb..bfb75bff 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -2786,6 +2786,8 @@ void UBDocumentController::importFile() if (fileInfo.suffix().toLower() == "ubx") { UBPersistenceManager::persistenceManager()->createDocumentProxiesStructure(docManager->importUbx(filePath, UBSettings::userDocumentDirectory()), true); + emit documentThumbnailsUpdated(this); // some documents might have been overwritten while not having the same page count + } else { UBSettings::settings()->lastImportFilePath->set(QVariant(fileInfo.absolutePath())); diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 59c72aad..6c5ae6d6 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -121,7 +121,7 @@ bool UBFileSystemUtils::copyFile(const QString &source, const QString &destinati bool UBFileSystemUtils::copy(const QString &source, const QString &destination, bool overwrite) { if (QFileInfo(source).isDir()) { - return copyDir(source, destination); + return copyDir(source, destination, overwrite); } else { return copyFile(source, destination, overwrite); } @@ -280,7 +280,7 @@ bool UBFileSystemUtils::deleteDir(const QString& pDirPath) } -bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath) +bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath, bool overwite) { if (pSourceDirPath == "" || pSourceDirPath == "." || pSourceDirPath == "..") return false; @@ -304,8 +304,7 @@ bool UBFileSystemUtils::copyDir(const QString& pSourceDirPath, const QString& pT } else { - QFile f(pSourceDirPath + "/" + dirContent.fileName()); - successSoFar = f.copy(pTargetDirPath + "/" + dirContent.fileName()); + successSoFar = copyFile(pSourceDirPath + "/" + dirContent.fileName(), pTargetDirPath + "/" + dirContent.fileName(), overwite); } } else diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index da74b069..a145177d 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -62,7 +62,7 @@ class UBFileSystemUtils : public QObject static bool deleteDir(const QString& pDirPath); - static bool copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath); + static bool copyDir(const QString& pSourceDirPath, const QString& pTargetDirPath, bool overwrite = false); static bool moveDir(const QString& pSourceDirPath, const QString& pTargetDirPath);