[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [vidalia/master] Automigrate TorExecutable, Torrc and DataDirectory to the new relative path handling



commit 6bcd0c1a346fa68e07564c6dc8dde1231f980979
Author: Tomás Touceda <chiiph@xxxxxxxxxxxxxx>
Date:   Mon May 28 20:49:30 2012 -0300

    Automigrate TorExecutable, Torrc and DataDirectory to the new relative path handling
---
 changes/settings_automigration |    2 +
 src/vidalia/MainWindow.cpp     |   46 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/changes/settings_automigration b/changes/settings_automigration
new file mode 100644
index 0000000..b832047
--- /dev/null
+++ b/changes/settings_automigration
@@ -0,0 +1,2 @@
+  o Automigrate TorExecutable, Torrc and DataDirectory config options
+    to the new relative path handling.
\ No newline at end of file
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index acf7bdd..85bc62e 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -1066,9 +1066,22 @@ MainWindow::start()
   }
 
   QString torrc = settings.getTorrc();
-  if(QDir(QFileInfo(torrc).filePath()).isRelative())
+  QFileInfo torrcInfo(torrc);
+
+  if(QDir(torrcInfo.filePath()).isRelative()) {
     torrc = QCoreApplication::applicationDirPath() + "/" + torrc;
 
+    QFileInfo newTorrcInfo(torrc);
+    if(!newTorrcInfo.exists() and torrcInfo.exists()) {
+      torrc = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(torrcInfo.absoluteFilePath());
+      vWarn("Automigrating configuration for Torrc:\nOld path: %1\nNew path: %2")
+        .arg(newTorrcInfo.filePath())
+        .arg(torrc);
+      settings.setTorrc(torrc);
+      torrc = QCoreApplication::applicationDirPath() + "/" + torrc;
+    }
+  }
+
   if(settings.bootstrap()) {
     QString boottorrc = settings.bootstrapFrom();
     vNotice(tr("Bootstrapping torrc from %1 to %2")
@@ -1089,9 +1102,22 @@ MainWindow::start()
 
   /* Specify Tor's data directory, if different from the default */
   QString dataDirectory = settings.getDataDirectory();
-  if(QDir(dataDirectory).isRelative())
+  QFileInfo dataDirectoryInfo(dataDirectory);
+
+  if(QDir(dataDirectory).isRelative()) {
     dataDirectory = QCoreApplication::applicationDirPath() + "/" + dataDirectory;
 
+    QFileInfo newDataDirectoryInfo(dataDirectory);
+    if(!newDataDirectoryInfo.exists() and dataDirectoryInfo.exists()) {
+      dataDirectory = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(dataDirectoryInfo.absoluteFilePath());
+      vWarn("Automigrating configuration for DataDirectory:\nOld path: %1\nNew path: %2")
+        .arg(newDataDirectoryInfo.absoluteFilePath())
+        .arg(dataDirectory);
+      settings.setDataDirectory(dataDirectory);
+      dataDirectory = QCoreApplication::applicationDirPath() + "/" + dataDirectory;
+    }
+  }
+
   QString expDataDirectory = QDir(expand_filename(dataDirectory)).canonicalPath();
   if (!dataDirectory.isEmpty())
     args << "DataDirectory" << expDataDirectory;
@@ -1147,8 +1173,22 @@ MainWindow::start()
   _isIntentionalExit = true;
   /* Kick off the Tor process */
   QString torExecutable = settings.getExecutable();
-  if(QDir(QFileInfo(torExecutable).filePath()).isRelative())
+  QFileInfo torExecutableInfo(torExecutable);
+
+  if(QDir(torExecutableInfo.filePath()).isRelative()) {
     torExecutable = QCoreApplication::applicationDirPath() + "/" + torExecutable;
+
+    QFileInfo newTorExecutableInfo(torExecutable);
+    if(!newTorExecutableInfo.exists() and torExecutableInfo.exists()) {
+      torExecutable = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(torExecutableInfo.absoluteFilePath());
+      vWarn("Automigrating configuration for TorExecutable:\nOld path: %1\nNew path: %2")
+        .arg(newTorExecutableInfo.filePath())
+        .arg(torExecutable);
+      settings.setExecutable(torExecutable);
+      torExecutable = QCoreApplication::applicationDirPath() + "/" + torExecutable;
+    }
+  }
+
   _torControl->start(torExecutable, args);
 }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits