summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/library/dao/directorydao.cpp23
-rw-r--r--src/test/directorydoatest.cpp2
3 files changed, 15 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 5ae136a612..c476f707b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
.sconf_temp
.sconsign.branch
.sconsign.dblite
+*.sqlite
cache
lib/*/*.a
lib/*/lib/*.a
diff --git a/src/library/dao/directorydao.cpp b/src/library/dao/directorydao.cpp
index 8654d39ef8..c68fdd4bb4 100644
--- a/src/library/dao/directorydao.cpp
+++ b/src/library/dao/directorydao.cpp
@@ -22,22 +22,25 @@ int DirectoryDAO::addDirectory(const QString& newDir) {
// Do nothing if the dir to add is a child of a directory that is already in
// the db.:
QStringList dirs = getDirs();
- bool childDir = false;
- bool parentDir = false;
+ QString childDir("");
+ QString parentDir("");
foreach (const QString& dir, dirs) {
- childDir = isChildDir(newDir, dir);
- parentDir= isChildDir(dir, newDir);
+ if (isChildDir(newDir, dir)) {
+ childDir = dir;
+ }
+ if (isChildDir(dir, newDir)) {
+ parentDir = dir;
+ }
}
- if (childDir) {
+ if (!childDir.isEmpty()) {
return ALREADY_WATCHING;
}
- if (parentDir) {
- // da a relocate here so that we from then on watch over the parent dir
- // TODO(kain88) actually implement this, right now send this so that the
- // unit test fails
- return SQL_ERROR;
+ if (!parentDir.isEmpty()) {
+ // removeing the old directory won't harm because we are adding the
+ // parent later in this function
+ removeDirectory(parentDir);
}
QSqlQuery query(m_database);
diff --git a/src/test/directorydoatest.cpp b/src/test/directorydoatest.cpp
index 5401a8f2c2..e9f17f95cc 100644
--- a/src/test/directorydoatest.cpp
+++ b/src/test/directorydoatest.cpp
@@ -77,7 +77,7 @@ TEST_F(DirectoryDAOTest, addDirTest) {
// the test db should be always empty when tests are started.
EXPECT_TRUE(dirs.size() == 1);
if ( dirs.size() > 0) {
- EXPECT_TRUE(dirs.at(0) == testdir);
+ EXPECT_TRUE(dirs.at(0) == "/TestDir");
}
}