summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/packagemanagercore.cpp
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-02-25 16:03:54 +0200
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2020-02-27 09:03:58 +0000
commit0cb97d954d14b8703169a2b7208eea660c9691a8 (patch)
treede8b79ea4e6ccd86044856a3cdc665a51ba7255a /src/libs/installer/packagemanagercore.cpp
parentccafccfb442b2f1b3d0b70f5d899716cb787ee5a (diff)
Add command line option to disable checking of free space on target3.2.2-rc
Also move functionality to PackageManagerCore::checkAvailableSpace() for more convenient later usage, if we want to use this without starting the Wizard GUI. Task-number: QTIFW-1602 Change-Id: I4f2d3cc78bc542475fe9c51b9364b1b221098e4a Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/packagemanagercore.cpp')
-rw-r--r--src/libs/installer/packagemanagercore.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 392dfb7b0..50671cebe 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -1943,6 +1943,109 @@ void PackageManagerCore::dropAdminRights()
}
/*!
+ Sets checkAvailableSpace based on value of \c check.
+*/
+void PackageManagerCore::setCheckAvailableSpace(bool check)
+{
+ d->m_checkAvailableSpace = check;
+}
+
+/*!
+ Checks available disk space if the feature is not explicitly disabled. Informative
+ text about space status can be retrieved by passing \c message parameter. Returns
+ \a true if there is sufficient free space on installation and temporary volumes.
+*/
+bool PackageManagerCore::checkAvailableSpace(QString &message) const
+{
+ const quint64 extraSpace = 256 * 1024 * 1024LL;
+ quint64 required(requiredDiskSpace());
+ quint64 tempRequired(requiredTemporaryDiskSpace());
+ if (required < extraSpace) {
+ required += 0.1 * required;
+ tempRequired += 0.1 * tempRequired;
+ } else {
+ required += extraSpace;
+ tempRequired += extraSpace;
+ }
+
+ quint64 repositorySize = 0;
+ const bool createLocalRepository = createLocalRepositoryFromBinary();
+ if (createLocalRepository && isInstaller()) {
+ repositorySize = QFile(QCoreApplication::applicationFilePath()).size();
+ // if we create a local repository, take that space into account as well
+ required += repositorySize;
+ }
+
+ qDebug() << "Installation space required:" << humanReadableSize(required) << "Temporary space "
+ "required:" << humanReadableSize(tempRequired) << "Local repository size:"
+ << humanReadableSize(repositorySize);
+
+ if (d->m_checkAvailableSpace) {
+ const VolumeInfo tempVolume = VolumeInfo::fromPath(QDir::tempPath());
+ const VolumeInfo targetVolume = VolumeInfo::fromPath(value(scTargetDir));
+
+ const quint64 tempVolumeAvailableSize = tempVolume.availableSize();
+ const quint64 installVolumeAvailableSize = targetVolume.availableSize();
+
+ // at the moment there is no better way to check this
+ if (targetVolume.size() == 0 && installVolumeAvailableSize == 0) {
+ qDebug().nospace() << "Cannot determine available space on device. "
+ "Volume descriptor: " << targetVolume.volumeDescriptor()
+ << ", Mount path: " << targetVolume.mountPath() << ". Continue silently.";
+ return true;
+ }
+
+ const bool tempOnSameVolume = (targetVolume == tempVolume);
+ if (tempOnSameVolume) {
+ qDebug() << "Tmp and install directories are on the same volume. Volume mount point:"
+ << targetVolume.mountPath() << "Free space available:"
+ << humanReadableSize(installVolumeAvailableSize);
+ } else {
+ qDebug() << "Tmp is on a different volume than the installation directory. Tmp volume mount point:"
+ << tempVolume.mountPath() << "Free space available:"
+ << humanReadableSize(tempVolumeAvailableSize) << "Install volume mount point:"
+ << targetVolume.mountPath() << "Free space available:"
+ << humanReadableSize(installVolumeAvailableSize);
+ }
+
+ if (tempOnSameVolume && (installVolumeAvailableSize <= (required + tempRequired))) {
+ message = tr("Not enough disk space to store temporary files and the "
+ "installation. %1 are available, while %2 are at least required.").arg(
+ humanReadableSize(installVolumeAvailableSize), humanReadableSize(required + tempRequired));
+ return false;
+ }
+
+ if (installVolumeAvailableSize < required) {
+ message = tr("Not enough disk space to store all selected components! %1 are "
+ "available while %2 are at least required.").arg(humanReadableSize(installVolumeAvailableSize),
+ humanReadableSize(required));
+ return false;
+ }
+
+ if (tempVolumeAvailableSize < tempRequired) {
+ message = tr("Not enough disk space to store temporary files! %1 are available "
+ "while %2 are at least required.").arg(humanReadableSize(tempVolumeAvailableSize),
+ humanReadableSize(tempRequired));
+ return false;
+ }
+
+ if (installVolumeAvailableSize - required < 0.01 * targetVolume.size()) {
+ // warn for less than 1% of the volume's space being free
+ message = tr("The volume you selected for installation seems to have sufficient space for "
+ "installation, but there will be less than 1% of the volume's space available afterwards.");
+ } else if (installVolumeAvailableSize - required < 100 * 1024 * 1024LL) {
+ // warn for less than 100MB being free
+ message = tr("The volume you selected for installation seems to have sufficient "
+ "space for installation, but there will be less than 100 MB available afterwards.");
+ }
+ }
+ message = QString::fromLatin1("%1 %2").arg(message, tr("Installation will use %1 of disk space.")
+ .arg(humanReadableSize(requiredDiskSpace()))).simplified();
+
+ return true;
+}
+
+/*!
Returns \c true if a process with \a name is running. On Windows, the comparison
is case-insensitive.