move path comparison to pathut

This commit is contained in:
Jean-Francois Dockes 2020-09-28 14:03:05 +02:00
parent eb58602b5d
commit 90f39ffacc
3 changed files with 25 additions and 20 deletions

View File

@ -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"));

View File

@ -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) {

View File

@ -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