Skip to content

Commit

Permalink
fix launchpad bug #1259077
Browse files Browse the repository at this point in the history
now isChildDir also returns true if both dirs are the same. I also added
a Test to check that there are no dirs added twice if one strigs ends
with "/"
  • Loading branch information
kain88-de committed Dec 14, 2013
1 parent 3afbf83 commit 15c0d41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 3 additions & 5 deletions src/library/browse/foldertreemodel.h
Expand Up @@ -11,11 +11,9 @@
#include "library/treeitem.h"

class TreeItem;
/*
* This class represents a folder item within the Browse Feature
* The class is derived from TreeItemModel to support lazy model
* initialization.
*/
// This class represents a folder item within the Browse Feature
// The class is derived from TreeItemModel to support lazy model
// initialization.

class FolderTreeModel : public TreeItemModel {
Q_OBJECT
Expand Down
8 changes: 3 additions & 5 deletions src/library/dao/directorydao.cpp
Expand Up @@ -21,7 +21,7 @@ void DirectoryDAO::initialize() {

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.:
// the db.
ScopedTransaction transaction(m_database);
QStringList dirs = getDirs();
QString childDir;
Expand All @@ -36,6 +36,7 @@ int DirectoryDAO::addDirectory(const QString& newDir) {
}

if (!childDir.isEmpty()) {
qDebug() << "return already watching";
return ALREADY_WATCHING;
}

Expand All @@ -60,15 +61,12 @@ int DirectoryDAO::addDirectory(const QString& newDir) {
bool DirectoryDAO::isChildDir(QString testDir, QString dirStr){
QDir test = QDir(testDir);
QDir dir = QDir(dirStr);

bool child = false;
bool child = dir == test;
while (test.cdUp()) {
// a parent of test is equal to dir
if (dir == test) {
child = true;
}
}

// qDebug() << "--- test related function ---";
// qDebug() << "testDir " << testDir;
// qDebug() << "dir" << dirStr;
Expand Down
7 changes: 6 additions & 1 deletion src/test/directorydoatest.cpp
Expand Up @@ -58,7 +58,12 @@ TEST_F(DirectoryDAOTest, addDirTest) {

// check that we don't add the directory again
success = m_DirectoryDao.addDirectory(testdir);
EXPECT_EQ(SQL_ERROR, success);
EXPECT_EQ(ALREADY_WATCHING, success);

// check that we don't add the directory again also if the string ends with
// "/".
success = m_DirectoryDao.addDirectory(testdir + "/");
EXPECT_EQ(ALREADY_WATCHING, success);

// check that we don't add a child directory
success = m_DirectoryDao.addDirectory(testChild);
Expand Down

0 comments on commit 15c0d41

Please sign in to comment.