mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
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
This commit is contained in:
parent
5c27b8400e
commit
e0941bdb4b
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include <shlwapi.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/cygwin.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
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];
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Carbon/Carbon.h>
|
||||
@ -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];
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user