From e0941bdb4bfc1f1371dbab1c2f96b83825614e3a Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 2 May 2009 16:39:14 +0000 Subject: [PATCH] Revert r29444 (to be soon replaced by Georg's solution). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29497 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/FileName.cpp | 51 ++++++++++++++++++++++++++++++--------- src/support/os.h | 5 ---- src/support/os_cygwin.cpp | 17 +------------ src/support/os_unix.cpp | 16 ------------ src/support/os_win32.cpp | 37 ---------------------------- 5 files changed, 40 insertions(+), 86 deletions(-) diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 58d2222ad7..8bc19e4052 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -927,22 +927,49 @@ docstring const FileName::relPath(string const & path) const } -bool operator==(FileName const & lhs, FileName const & rhs) +// Note: According to Qt, QFileInfo::operator== is undefined when +// both files do not exist (Qt4.5 gives true for all non-existent +// files, while Qt4.4 compares the filenames). +// see: +// http://www.qtsoftware.com/developer/task-tracker/ +// index_html?id=248471&method=entry. +bool operator==(FileName const & l, FileName const & r) { - // Avoid unnecessary checks below - if (lhs.empty() || rhs.empty()) - return lhs.empty() && rhs.empty(); + // FIXME: In future use Qt. + // Qt 4.4: We need to solve this warning from Qt documentation: + // * Long and short file names that refer to the same file on Windows are + // treated as if they referred to different files. + // This is supposed to be fixed for Qt5. + FileName const lhs(os::internal_path(l.absFilename())); + FileName const rhs(os::internal_path(r.absFilename())); - // Firstly, compare the filenames. - if (QString::compare(toqstr(lhs.absFilename()), - toqstr(rhs.absFilename()), - os::isFilesystemCaseSensitive() ? - Qt::CaseSensitive : Qt::CaseInsensitive) == 0) { - return true; + if (lhs.empty()) + // QFileInfo::operator==() returns false if the two QFileInfo are empty. + return rhs.empty(); + + if (rhs.empty()) + // Avoid unnecessary checks below. + return false; + + lhs.d->refresh(); + rhs.d->refresh(); + + if (!lhs.d->fi.isSymLink() && !rhs.d->fi.isSymLink()) { + // Qt already checks if the filesystem is case sensitive or not. + // see note above why the extra check with fileName is needed. + return lhs.d->fi == rhs.d->fi + && lhs.d->fi.fileName() == rhs.d->fi.fileName(); } - // They don't match, so check whether they point to the same file. - return os::isSameFile(lhs.toFilesystemEncoding(), rhs.toFilesystemEncoding()); + // FIXME: When/if QFileInfo support symlink comparison, remove this code. + QFileInfo fi1(lhs.d->fi); + if (fi1.isSymLink()) + fi1 = QFileInfo(fi1.symLinkTarget()); + QFileInfo fi2(rhs.d->fi); + if (fi2.isSymLink()) + fi2 = QFileInfo(fi2.symLinkTarget()); + // see note above why the extra check with fileName is needed. + return fi1 == fi2 && fi1.fileName() == fi2.fileName(); } diff --git a/src/support/os.h b/src/support/os.h index dbc9b61859..f96fa64384 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -112,11 +112,6 @@ bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW); */ bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW); -/** Check whether two filenames point to the same file. - * \warning the filenames must already be in the filesystem encoding. - */ -bool isSameFile(std::string const & fileone, std::string const & filetwo); - /** Resolves a path such that it does not contain '.', '..', or symbolic links. * \warning the path must already be in the filesystem encoding. * \returns the resolved path in utf8 encoding. diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index 7479c98afd..43b0a16192 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -28,8 +28,8 @@ #include #include #include + #include -#include using namespace std; @@ -284,21 +284,6 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) } -bool isSameFile(string const & fileone, string const & filetwo) -{ - struct stat st1; - struct stat st2; - - if (::stat(fileone.c_str(), &st1) == 0 - && ::stat(filetwo.c_str(), &st2) == 0) { - return st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev; - } - - // One or both files cannot be accessed. - return false; -} - - string real_path(string const & path) { char rpath[PATH_MAX + 1]; diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index a9c040c6c9..4bbd76fe1c 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -19,7 +19,6 @@ #include #include -#include #ifdef __APPLE__ #include @@ -220,21 +219,6 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) } -bool isSameFile(string const & fileone, string const & filetwo) -{ - struct stat st1; - struct stat st2; - - if (::stat(fileone.c_str(), &st1) == 0 - && ::stat(filetwo.c_str(), &st2) == 0) { - return st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev; - } - - // One or both files cannot be accessed. - return false; -} - - string real_path(string const & path) { char rpath[PATH_MAX + 1]; diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index 62ef4e9970..2e7b826203 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -390,43 +390,6 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) } -bool isSameFile(string const & fileone, string const & filetwo) -{ - HANDLE h1 = CreateFile(fileone.c_str(), 0, - FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - HANDLE h2 = CreateFile(filetwo.c_str(), 0, - FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - - if (h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) { - // One or both files cannot be accessed. - if (h1 != INVALID_HANDLE_VALUE) - CloseHandle(h1); - if (h2 != INVALID_HANDLE_VALUE) - CloseHandle(h2); - return false; - } - - BY_HANDLE_FILE_INFORMATION info1; - BY_HANDLE_FILE_INFORMATION info2; - bool samefile = false; - if (GetFileInformationByHandle(h1, &info1) != 0 - && GetFileInformationByHandle(h2, &info2) != 0) { - // Serial number of the volumes containing the files. - ULONG st1_dev = info1.dwVolumeSerialNumber; - ULONG st2_dev = info2.dwVolumeSerialNumber; - // Unique identifiers associated to the files on the volumes. - ULONGLONG highbits = info1.nFileIndexHigh & 0x0000FFFF; - ULONGLONG st1_ino = (highbits << sizeof(ULONG)) | info1.nFileIndexLow; - highbits = info2.nFileIndexHigh & 0x0000FFFF; - ULONGLONG st2_ino = (highbits << sizeof(ULONG)) | info2.nFileIndexLow; - samefile = st1_ino == st2_ino && st1_dev == st2_dev; - } - CloseHandle(h1); - CloseHandle(h2); - return samefile; -} - - string real_path(string const & path) { // See http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx