qet.addElement: report an unreadable symbol instead of a collision

A symbol file that exists but cannot be read has a null uuid, which the
check against the copy already embedded reported as "would collide with a
different element". Say that the file could not be read, with its full
path and length, since a long path is the usual cause on Windows.

tst_unreadableelement makes the file unreadable through its permissions
and fails on master with the old message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 22:22:18 +13:00
parent af184ed986
commit e94c6d82c9
3 changed files with 139 additions and 0 deletions
+12
View File
@@ -86,6 +86,7 @@
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QDir>
#include <QDomDocument>
#include <QFileInfo>
#include <QFont>
@@ -677,6 +678,17 @@ QString QetScriptApi::addElement(int folioIndex, const QString &locationPath, do
const QString import_path = location.isFileSystem()
? QStringLiteral("import/") + location.collectionPath(false)
: location.collectionPath(false);
// An element file that exists but cannot be read gives a null
// uuid(), which the collision check below would misreport as "a
// different element" -- say what actually went wrong instead.
if (location.isFileSystem()
&& location.pugiXml().document_element().empty()) {
const QString file = QDir::toNativeSeparators(
QFileInfo(location.fileSystemPath()).absoluteFilePath());
log(QStringLiteral("qet.addElement: could not read element '%1' (file '%2', "
"%3 characters)").arg(locationPath, file).arg(file.size()));
return QString();
}
const ElementsLocation existing(import_path, m_project);
if (existing.exist() && existing.uuid() != location.uuid()) {
log(QStringLiteral("qet.addElement: '%1' would collide with a different element "