From: hama Date: Thu, 25 Feb 2016 23:38:13 +0000 (+0100) Subject: rebackgui: linux things X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=243073eadf0f7ae09d2b6cb08380c8e1d7426fc0;p=reqt rebackgui: linux things --- diff --git a/appl/rebackgui/BackupUtils.cpp b/appl/rebackgui/BackupUtils.cpp index 620ec14..0e9538d 100644 --- a/appl/rebackgui/BackupUtils.cpp +++ b/appl/rebackgui/BackupUtils.cpp @@ -10,9 +10,14 @@ */ #include "backupgui.hpp" +enum { + LOC_FIND_TARGET_1 = LOC_FIRST_OF(LOC_REBACKGUI_BACKUPUTILS), // 20501 + LOC_FIND_TARGET_2, // 20502 +}; + + BackupUtils::BackupUtils() { - } /** * Converts a date time to a string. @@ -40,11 +45,28 @@ QString BackupUtils::findTarget(const BackupItem& item, ReLogger* logger) { QString rc; #if defined __linux__ - if (item.m_target.startsWith(";/")){ + if (item.m_target.isEmpty()){ + // nothing to do + } else if (item.m_target.startsWith(";/")){ // the path is an absolute path on a fixed disk: rc = item.m_target.mid(1); } else { - + QStringList parts = item.m_target.split(';'); + QStringList args; + args << "/usr/local/bin/osconnect.pl" + << "search-target" << parts.at(0) + << parts.at(1) + << "/media/EFI_system/backup"; + QByteArray output = ReProcess::executeAndRead("/usr/bin/perl", args, 20); + QByteArrayList lines = output.split('\n'); + if (lines.count() < 2){ + logger->log(LOG_ERROR, LOC_FIND_TARGET_1, "missing lines from osconnect.pl"); + } else if (lines.at(1).startsWith("+++")) { + logger->logv(LOG_ERROR, LOC_FIND_TARGET_2, "mounting failed: %s", + lines.at(1).mid(3).constData()); + } else { + rc = QString::fromUtf8(lines.at(0)); + } } #elif defined _WIN32 QStringList drives = ReFileUtils::findRootDirs(); @@ -122,4 +144,32 @@ QDateTime BackupUtils::stringToDate(const QString &dateTime) return rc; } +QString BackupUtils::targetDescription(const QString& backupPath, ReLogger *logger){ + QString rc; +#if defined __linux__ + if (true){ + // nothing to do + } else if (true){ + // the path is an absolute path on a fixed disk: + } else { + QStringList args; + args << "/usr/local/bin/osconnect.pl" + << "find-label" + << backupPath + << "/media/EFI_system/backup"; + QByteArray output = ReProcess::executeAndRead("/usr/bin/perl", args, 20); + QByteArrayList lines = output.split('\n'); + if (lines.count() < 2){ + logger->log(LOG_ERROR, LOC_FIND_TARGET_1, "missing lines from osconnect.pl"); + } else if (lines.at(1).startsWith("+++")) { + logger->logv(LOG_ERROR, LOC_FIND_TARGET_2, "mounting failed: %s", + lines.at(1).mid(3).constData()); + } else { + rc = QString::fromUtf8(lines.at(0)); + } + } +#elif defined _WIN32 +#endif + return rc; +} diff --git a/appl/rebackgui/BackupUtils.hpp b/appl/rebackgui/BackupUtils.hpp index 43f35bd..3c41797 100644 --- a/appl/rebackgui/BackupUtils.hpp +++ b/appl/rebackgui/BackupUtils.hpp @@ -8,20 +8,21 @@ * More info: http://unlicense.org * The latest sources: https://github.com/republib */ -#ifndef BACKUPUTILS_H -#define BACKUPUTILS_H - - -class BackupUtils -{ -public: - BackupUtils(); -public: - static QString dateToString(const QDateTime& dateTime); - static QString findTarget(const BackupItem& item, ReLogger* logger); - static QString nameOfTargetDescription(const QString &path); - static bool prepareTarget(const QString &path, BackupItem &item, ReLogger *logger); - static QDateTime stringToDate(const QString& dateTime); -}; - -#endif // BACKUPUTILS_H +#ifndef BACKUPUTILS_H +#define BACKUPUTILS_H + + +class BackupUtils +{ +public: + BackupUtils(); +public: + static QString dateToString(const QDateTime& dateTime); + static QString findTarget(const BackupItem& item, ReLogger* logger); + static QString nameOfTargetDescription(const QString &path); + static bool prepareTarget(const QString &path, BackupItem &item, ReLogger *logger); + static QDateTime stringToDate(const QString& dateTime); + static QString targetDescription(const QString& backupPath, ReLogger *logger); +}; + +#endif // BACKUPUTILS_H diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 2c4998c..c430ab9 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -573,6 +573,9 @@ void MainWindow::onSelectTarget(){ if (! BackupUtils::prepareTarget(dir, item, &m_logger)) say(LOG_INFO, tr("target initialized with %1") .arg(BackupUtils::nameOfTargetDescription(dir))); + else { + item.m_target = BackupUtils::targetDescription(dir, &m_logger); + } } } diff --git a/appl/rebackgui/osconnect.pl b/appl/rebackgui/osconnect.pl old mode 100644 new mode 100755 index 04f24c7..1cb2275 --- a/appl/rebackgui/osconnect.pl +++ b/appl/rebackgui/osconnect.pl @@ -6,24 +6,57 @@ my $mode = shift; my %devs; my (%g_devOfPoint, %g_pointOfDev, %g_devOfLabel, %g_labelOfDev); -&FindLabels; -&FindMountPoints; if ($mode eq "find-label"){ my $targetPath = shift; if (! -d $targetPath){ &Usage("not a directory: $targetPath"); } + &FindLabels; + &FindMountPoints; &PrintLabelAndRelPath($targetPath); } elsif ($mode eq "search-target"){ my $label = shift; my $relPath = shift; + my $testDir = shift; + $label =~ s/L=//; &Usage("missing label") unless $label; &Usage("missing relative path") unless $relPath; - my $dev = %g_devOfLabel{$label}; - if ($dev ne ""){ - my $mountPoint = $g_pointOfDev{$dev}; - if ($mountPoint ne ""){ - print "$mountPoint/$relPath\n"; + if ($testDir ne ""){ + print "$testDir\nmounted\n"; + } else { + &FindLabels; + &FindMountPoints; + my $dev = %g_devOfLabel{$label}; + + if ($dev ne ""){ + my $mountPoint = $g_pointOfDev{$dev}; + if ($mountPoint ne ""){ + print "$mountPoint/$relPath\nmounted\n"; + } else { + $mountPoint = $label; + $mountPoint =~ s/[^\w!=%.+-]+/_/g; + $mountPoint =~ s/__+/_/g; + $mountPoint = "/media/$mountPoint"; + mkdir $mountPoint, 0777 unless $mountPoint; + my $dir = $mountPoint; + my $no = 1; + while(IsMounted($dir)){ + $dir = $mountPoint . ++$no; + } + $mountPoint = $dir; + mkdir $mountPoint, 0777 unless -d $mountPoint; + Exec("mount 'LABEL=$label' $mountPoint"); + &FindMountPoints; + $dir = "$mountPoint/$relPath"; + my $isMounted = IsMounted($mountPoint); + if ($isMounted && -d $dir){ + print "$dir\nunmounted\n"; + } else { + my $error = ! $isMounted ? "cannot mount '$label' to $mountPoint" + : "missing $relPath on '$label'"; + print "\n+++ $error\n"; + } + } } } } else { @@ -40,15 +73,23 @@ osconnect find-label Output: L=