]> gitweb.hamatoma.de Git - reqt/commitdiff
rebackgui: enforce shadow dir, format check
authorhama <hama@siduction.net>
Sun, 2 Oct 2016 08:40:01 +0000 (10:40 +0200)
committerhama <hama@siduction.net>
Sun, 2 Oct 2016 08:40:01 +0000 (10:40 +0200)
* creation of the shadow directory with sudo (if not exists)
* no crash if ';' is missed in the target
* new ReProcess.cpp

.gitignore
appl/rebackgui/BackupEngine.cpp
appl/rebackgui/BackupEngine.hpp
appl/rebackgui/BackupUtils.cpp
appl/rebackgui/mainwindow.cpp
appl/refind/ReProcess.cpp [new symlink]

index 76d98cb793ac12818abc1d1afdb1d6497b33fddf..f39780d7807f25c0db0b7c2e1d62fd1910e96e9e 100644 (file)
@@ -14,3 +14,6 @@ appl/build-reidos-Desktop-Debug/
 .metadata
 2github
 
+.rebackgui.target
+appl/build-rebackgui-Desktop_Qt_5_6_0_GCC_64bit-Debug/
+appl/rebackgui/.rebackgui.target
index 4a4cb323024b33c93f0555aef2205b2c5a4e5a24..639cda283ae6cee5ed6a301c597ecb21aa32cbea 100644 (file)
@@ -935,6 +935,39 @@ void SearchTargetTask::searchOneDirectory(const QString& target,
        }
 }
 
+/**
+ * Creates the base directory for shadowing.
+ *
+ * @param base the full path of the base directory
+ * @return             <code>true</code>: the base directory exists and is writeable
+ */
+bool SearchTargetTask::ensureShadowBase(const QString& base){
+       bool rc = ReFileUtils::isDirectory(base);
+       if (! rc){
+#if defined __linux__
+               QStringList args;
+               args << "/bin/mkdir" << base;
+               QByteArray errorMsg;
+               ReSuccess_t rc2 =  ReProcess::executeSilent("/usr/bin/sudo", args, 30, &errorMsg);
+               if (! rc2)
+                       error(QString(errorMsg));
+
+               rc = ReFileUtils::isDirectory(base);
+#endif
+       }
+#if defined __linux__
+       if (rc){
+               QStringList args;
+               args.clear();           args << "/bin/chmod" << "uog=rwx" << base;
+               QByteArray errorMsg;
+               ReSuccess_t rc2 =  ReProcess::executeSilent("/usr/bin/sudo", args, 30, &errorMsg);
+               if (! rc2)
+                       error(QString(errorMsg));
+       }
+#endif
+       return rc;
+}
+
 /**
  * Moves a target directory to the shadow directory and delegate the removing files.
  *
@@ -949,20 +982,19 @@ void SearchTargetTask::moveToShadow(const QString& target, const QString& relPat
                QString targetName = shadowDir;
                int pos = targetName.length() / 2;
                while(pos < shadowDir.length()){
-               char cc = '0' - 1;
-               do{
-                       targetName[pos] = ++cc;
-               } while (cc <= 'Z' && QFileInfo(targetName).exists());
-               if (cc <= 'Z'){
-                       if (rename(I18N::s2b(shadowDir).constData(),
-                                               I18N::s2b(targetName).constData()) != 0)
-                               error(QObject::tr("kann Schattenverzeichnis nicht umbenennen: %1 -> %2")
-                                         .arg(shadowDir, targetName));
-                       else break;
-               }
-               pos++;
+                       char cc = '0' - 1;
+                       do{
+                               targetName[pos] = ++cc;
+                       } while (cc <= 'Z' && QFileInfo(targetName).exists());
+                       if (cc <= 'Z'){
+                               if (rename(I18N::s2b(shadowDir).constData(),
+                                                  I18N::s2b(targetName).constData()) != 0)
+                                       error(QObject::tr("kann Schattenverzeichnis nicht umbenennen: %1 -> %2")
+                                                 .arg(shadowDir, targetName));
+                               else break;
+                       }
+                       pos++;
                }
-
        }
        if (! ReFileUtils::makeDirWithParents(shadowDir)){
 
@@ -987,6 +1019,7 @@ void SearchTargetTask::run()
        qint64 start = QDateTime::currentMSecsSinceEpoch();
        m_searchReady = false;
        QString targetDir, sourceDir;
+       ensureShadowBase(m_shadowBaseDir);
        for (int ix = 0; ! m_shouldStop && ix < m_sourceDirs.size(); ix++){
                sourceDir = m_sourceDirs.at(ix);
                targetDir = m_targetDirs.at(ix);
index 598eac1011327d2f6e8476654a1e7cd239f84b31..5b68fc249ab54c66fe4530eefa289b6688206640 100644 (file)
@@ -191,6 +191,7 @@ public:
 public:
        virtual void run();
 private:
+       bool ensureShadowBase(const QString& base);
        void moveToShadow(const QString& target, const QString& relPath, int index);
        bool removeOlder(const QString& directory, const QDateTime& time);
        void searchOneDirectory(const QString& target, const QString& source,
index 41e5d1391184c7dc4b1bd6dfd9164863f0417378..ed5c8f87b09980abcb7b7ee698aa0f0b3b45c6ee 100644 (file)
@@ -13,6 +13,7 @@
 enum {
        LOC_FIND_TARGET_1 = LOC_FIRST_OF(LOC_REBACKGUI_BACKUPUTILS), // 20501
        LOC_FIND_TARGET_2, // 20502
+    LOC_FIND_TARGET_3, // 20503
 };
 
 
@@ -89,29 +90,34 @@ QString BackupUtils::findTarget(const BackupItem& item, MainWindow& mainWindow,
                rc = item.m_target.mid(1);
        } else {
                ReBlockDevices& devices = ReBlockDevices::instance();
-               QStringList parts = item.m_target.split(';');
-               QStringList args;
-               QString label = parts.at(0);
-               QString relativePath = parts.at(1);
-               if (label.startsWith("L="))
-                       label = label.mid(2);
-               const ReBlockDevice* device = devices.findByLabel(label);
-               if (device != NULL){
-                       ReMountInfo& mountInfo = ReMountInfo::instance();
-                       if (mountInfo.m_mountPointOfDevice.contains(device->m_device)){
-                               rc = mountInfo.m_mountPointOfDevice.value(device->m_device);
-                                       + OS_SEPARATOR + relativePath;
-                       } else {
-                               QStringList args;
-                               QString mountPath = "/media/" + label;
-                               ReFileUtils::makeDir(mountPath, mainWindow.logger());
+        if (item.m_target.indexOf(';') < 0) {
+            mainWindow.say(LOG_ERROR, QObject::tr("wrong target format. Missing ';': %1").arg(
+                        item.m_target));
+        } else {
+            QStringList parts = item.m_target.split(';');
+            QStringList args;
+            QString label = parts.at(0);
+            QString relativePath = parts.at(1);
+            if (label.startsWith("L="))
+                label = label.mid(2);
+            const ReBlockDevice* device = devices.findByLabel(label);
+            if (device != NULL){
+                ReMountInfo& mountInfo = ReMountInfo::instance();
+                if (mountInfo.m_mountPointOfDevice.contains(device->m_device)){
+                    rc = mountInfo.m_mountPointOfDevice.value(device->m_device)
+                            + OS_SEPARATOR + relativePath;
+                } else {
+                    QStringList args;
+                    QString mountPath = "/media/" + label;
+                    ReFileUtils::makeDir(mountPath, mainWindow.logger());
 
-                               if (ReMountInfo::mount(device->m_device, mountPath, &mainWindow)){
-                                       tempoararyMounted = device->m_device;
-                               }
-                       }
-               }
-       }
+                    if (ReMountInfo::mount(device->m_device, mountPath, &mainWindow)){
+                        tempoararyMounted = device->m_device;
+                    }
+                }
+            }
+        }
+    }
 #elif defined _WIN32
        (void) tempoararyMounted;
        QStringList drives = ReFileUtils::findRootDirs();
index 1f41ef44d7a32757c65306c52ea1d5617c5d1e03..a172085033c3428f66f5579164aed2d70f80e0ad 100644 (file)
@@ -16,7 +16,7 @@
 #include "base/retrace.hpp"
 DECLARE_TRACER(s_traceMain, "/tmp/bup_main.log");
 
-const QString VERSION("2016.06.01");
+const QString VERSION("2016.10.01");
 
 /**
  * Constructor.
diff --git a/appl/refind/ReProcess.cpp b/appl/refind/ReProcess.cpp
new file mode 120000 (symlink)
index 0000000..81ea9b6
--- /dev/null
@@ -0,0 +1 @@
+../../base/ReProcess.cpp
\ No newline at end of file