From 90f39ffacc40c691a6c985f747c44c6c4bf544e1 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 28 Sep 2020 14:03:05 +0200 Subject: [PATCH] move path comparison to pathut --- src/qtgui/uiprefs_w.cpp | 23 +++-------------------- src/utils/pathut.cpp | 20 ++++++++++++++++++++ src/utils/pathut.h | 2 ++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index 8f4e3022..1f5dcfd3 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -255,7 +255,7 @@ void UIPrefsDialog::setFromPrefs() for (const auto& dbdir : prefs.activeExtraDbs) { auto items = idxLV->findItems(path2qs(dbdir), - Qt::MatchFixedString|Qt::MatchCaseSensitive); + Qt::MatchFixedString|Qt::MatchCaseSensitive); for (auto& entry : items) { entry->setCheckState(Qt::Checked); } @@ -589,23 +589,6 @@ void UIPrefsDialog::delExtraDbPB_clicked() } } -static bool samedir(const string& dir1, const string& dir2) -{ -#ifdef _WIN32 - return !dir1.compare(dir2); -#else - struct stat st1, st2; - if (stat(dir1.c_str(), &st1)) - return false; - if (stat(dir2.c_str(), &st2)) - return false; - if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) { - return true; - } - return false; -#endif -} - void UIPrefsDialog::on_showTrayIconCB_clicked() { if (!showTrayIconCB->checkState()) { @@ -658,7 +641,7 @@ void UIPrefsDialog::addExtraDbPB_clicked() " stripping option")); return; } - if (samedir(dbdir, theconfig->getDbDir())) { + if (path_samefile(dbdir, theconfig->getDbDir())) { QMessageBox::warning(0, "Recoll", tr("This is the main/local index!")); return; } @@ -666,7 +649,7 @@ void UIPrefsDialog::addExtraDbPB_clicked() for (int i = 0; i < idxLV->count(); i++) { QListWidgetItem *item = idxLV->item(i); string existingdir = qs2path(item->text()); - if (samedir(dbdir, existingdir)) { + if (path_samefile(dbdir, existingdir)) { QMessageBox::warning( 0, "Recoll", tr("The selected directory is already in the " "index list")); diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 0270fcfa..8484181c 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -969,6 +969,26 @@ long long path_filesize(const string& path) return (long long)st.st_size; } +bool path_samefile(const std::string& p1, const std::string& p2) +{ +#ifdef _WIN32 + std::string cp1, cp2; + cp1 = path_canon(p1); + cp2 = path_canon(p2); + return !cp1.compare(cp2); +#else + struct stat st1, st2; + if (stat(p1.c_str(), &st1)) + return false; + if (stat(p2.c_str(), &st2)) + return false; + if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) { + return true; + } + return false; +#endif +} + int path_fileprops(const std::string path, struct PathStat *stp, bool follow) { if (nullptr == stp) { diff --git a/src/utils/pathut.h b/src/utils/pathut.h index f86f62dc..be1b4206 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -75,6 +75,8 @@ extern bool path_isfile(const std::string& path, bool follow = false); /// Retrieve file size extern long long path_filesize(const std::string& path); +bool path_samefile(const std::string& p1, const std::string& p2); + /// Retrieve essential file attributes. This is used rather than a /// bare stat() to ensure consistent use of the time fields (on /// windows, we set ctime=mtime as ctime is actually the creation