diff options
Diffstat (limited to 'src/libs/installer/extractarchiveoperation.cpp')
-rw-r--r-- | src/libs/installer/extractarchiveoperation.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/libs/installer/extractarchiveoperation.cpp b/src/libs/installer/extractarchiveoperation.cpp index 5ff2d9a1a..b00a67190 100644 --- a/src/libs/installer/extractarchiveoperation.cpp +++ b/src/libs/installer/extractarchiveoperation.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2022 The Qt Company Ltd. +** Copyright (C) 2023 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -103,7 +103,7 @@ void ExtractArchiveOperation::backup() return; } - const bool hasAdminRights = (AdminAuthorization::hasAdminRights() || RemoteClient::instance().isActive()); + const bool hasAdminRights = (packageManager() && packageManager()->hasAdminRights()); const bool canCreateSymLinks = QInstaller::canCreateSymbolicLinks(); bool needsAdminRights = false; @@ -178,9 +178,13 @@ bool ExtractArchiveOperation::performOperation() QString installDir = targetDir; // If we have package manager in use (normal installer run) then use // TargetDir for saving filenames, otherwise those would be saved to - // extracted folder. - if (packageManager()) - installDir = packageManager()->value(scTargetDir); + // extracted folder. Also initialize installerbasebinary which we use later + // to check if the extracted file in question is the maintenancetool itself. + QString installerBaseBinary; + if (PackageManagerCore *core = packageManager()) { + installDir = core->value(scTargetDir); + installerBaseBinary = core->toNativeSeparators(core->replaceVariables(core->installerBaseBinary())); + } const QString resourcesPath = installDir + QLatin1Char('/') + QLatin1String("installerResources"); QString fileDirectory = resourcesPath + QLatin1Char('/') + archivePath.section(QLatin1Char('/'), 1, 1, @@ -193,20 +197,7 @@ bool ExtractArchiveOperation::performOperation() QFileInfo targetDirectoryInfo(fileDirectory); - // We need to create the directory structure step-by-step to avoid a rare race condition - // on Windows. QDir::mkpath() doesn't check if the leading directories were created elsewhere - // (like from within another thread) after the initial check that the given path requires - // creating also parent directories. - // - // On Unix patforms this case is handled by QFileSystemEngine though. - QDir resourcesDir(resourcesPath); - if (!resourcesDir.exists()) - resourcesDir.mkdir(resourcesPath); - - QDir resourceFileDir(targetDirectoryInfo.absolutePath()); - if (!resourceFileDir.exists()) - resourceFileDir.mkdir(targetDirectoryInfo.absolutePath()); - + QInstaller::createDirectoryWithParents(targetDirectoryInfo.absolutePath()); setDefaultFilePermissions(resourcesPath, DefaultFilePermissions::Executable); setDefaultFilePermissions(targetDirectoryInfo.absolutePath(), DefaultFilePermissions::Executable); @@ -215,9 +206,17 @@ bool ExtractArchiveOperation::performOperation() setDefaultFilePermissions(file.fileName(), DefaultFilePermissions::NonExecutable); QDataStream out (&file); for (int i = 0; i < files.count(); ++i) { + if (!installerBaseBinary.isEmpty() && files[i].startsWith(installerBaseBinary)) { + // Do not write installerbase binary filename to extracted files. Installer binary + // is maintenance tool program, the binary is removed elsewhere + // when we do full uninstall. + files.clear(); + break; + } files[i] = replacePath(files.at(i), installDir, QLatin1String(scRelocatable)); } - out << files; + if (!files.isEmpty()) + out << files; setValue(QLatin1String("files"), file.fileName()); file.close(); } else { @@ -255,10 +254,14 @@ bool ExtractArchiveOperation::undoOperation() if (!readDataFileContents(targetDir, &files)) return false; } - startUndoProcess(files); + if (!files.isEmpty()) + startUndoProcess(files); if (!useStringListType) deleteDataFile(m_relocatedDataFileName); + // Remove the installerResources directory if it is empty. + QDir(targetDir).rmdir(QLatin1String("installerResources")); + return true; } |