Jürgen Spitzmüller schreef:
Vincent van Ravesteijn wrote:
And what about the patch from Georg ? That patch sort of solved the
problem too. This patch was less intrusive and I already tested that.
If it was upto me, I would revert this commit and commit Georg's patch.
Do you have a pointer to this patch at hand?
Jürgen
I believe this was the patch.
Vincent
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp (Revision 28885)
+++ src/insets/InsetInclude.cpp (Arbeitskopie)
@@ -446,7 +446,7 @@ int InsetInclude::latex(odocstream & os,
// if incfile is relative, make it relative to the master
// buffer directory.
- if (!FileName(incfile).isAbsolute()) {
+ if (!FileName::isAbsolute(incfile)) {
// FIXME UNICODE
incfile =
to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
from_utf8(masterBuffer->filePath())));
Index: src/insets/InsetBibtex.cpp
===================================================================
--- src/insets/InsetBibtex.cpp (Revision 28885)
+++ src/insets/InsetBibtex.cpp (Arbeitskopie)
@@ -219,7 +219,7 @@ static string normalizeName(Buffer const
OutputParams const & runparams, string const & name, string const & ext)
{
string const fname = makeAbsPath(name, buffer.filePath()).absFilename();
- if (FileName(name).isAbsolute() || !FileName(fname +
ext).isReadableFile())
+ if (FileName::isAbsolute(name) || !FileName(fname +
ext).isReadableFile())
return name;
if (!runparams.nice)
return fname;
@@ -408,8 +408,7 @@ support::FileNameList InsetBibtex::getBi
vector<docstring>::const_iterator it = bibfilelist.begin();
vector<docstring>::const_iterator en = bibfilelist.end();
for (; it != en; ++it) {
- FileName const file =
- findtexfile(changeExtension(to_utf8(*it), "bib"),
"bib");
+ FileName const file = getBibTeXPath(*it, buffer());
if (!file.empty())
vec.push_back(file);
Index: src/insets/ExternalSupport.cpp
===================================================================
--- src/insets/ExternalSupport.cpp (Revision 28885)
+++ src/insets/ExternalSupport.cpp (Arbeitskopie)
@@ -130,7 +130,7 @@ string const doSubstitution(InsetExterna
relToParentPath, use_latex_path,
PROTECT_EXTENSION,
ESCAPE_DOTS);
- if (FileName(filename).isAbsolute()) {
+ if (FileName::isAbsolute(filename)) {
result = subst_path(result, "$$AbsOrRelPathMaster",
abspath, use_latex_path,
PROTECT_EXTENSION,
Index: src/LaTeX.cpp
===================================================================
--- src/LaTeX.cpp (Revision 28885)
+++ src/LaTeX.cpp (Arbeitskopie)
@@ -773,12 +773,13 @@ bool handleFoundFile(string const & ff,
// (1) foundfile is an
// absolute path and should
// be inserted.
- FileName absname(foundfile);
- if (absname.isAbsolute()) {
+ FileName absname;
+ if (FileName::isAbsolute(foundfile)) {
LYXERR(Debug::DEPEND, "AbsolutePath file: " << foundfile);
// On initial insert we want to do the update at once
// since this file cannot be a file generated by
// the latex run.
+ absname.set(foundfile);
if (!insertIfExists(absname, head)) {
// check for spaces
string strippedfile = foundfile;
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp (Revision 28885)
+++ src/frontends/qt4/GuiView.cpp (Arbeitskopie)
@@ -1439,7 +1439,7 @@ void GuiView::openDocument(string const
if (!fullname.onlyPath().isDirectory()) {
Alert::warning(_("Invalid filename"),
- bformat(_("The directory in the given
path\n%1$s\ndoes not exists."),
+ bformat(_("The directory in the given
path\n%1$s\ndoes not exist."),
from_utf8(fullname.absFilename())));
return;
}
Index: src/Session.cpp
===================================================================
--- src/Session.cpp (Revision 28885)
+++ src/Session.cpp (Arbeitskopie)
@@ -57,11 +57,11 @@ void LastFilesSection::read(istream & is
if (c == '[')
break;
getline(is, tmp);
- FileName const file(tmp);
- if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' ||
!file.isAbsolute())
+ if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ' ||
!FileName::isAbsolute(tmp))
continue;
// read lastfiles
+ FileName const file(tmp);
if (file.exists() && !file.isDirectory()
&& lastfiles.size() < num_lastfiles)
lastfiles.push_back(file);
@@ -111,10 +111,10 @@ void LastOpenedSection::read(istream & i
if (c == '[')
break;
getline(is, tmp);
- FileName const file(tmp);
- if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' ||
!file.isAbsolute())
+ if (tmp.empty() || tmp[0] == '#' || tmp[0] == ' ' ||
!FileName::isAbsolute(tmp))
continue;
+ FileName const file(tmp);
if (file.exists() && !file.isDirectory())
lastopened.push_back(file);
else
@@ -165,9 +165,9 @@ void LastFilePosSection::read(istream &
itmp >> filepos.pos;
itmp.ignore(2); // ignore ", "
getline(itmp, fname);
- FileName const file(fname);
- if (!file.isAbsolute())
+ if (!FileName::isAbsolute(fname))
continue;
+ FileName const file(fname);
if (file.exists() && !file.isDirectory()
&& lastfilepos.size() < num_lastfilepos)
lastfilepos[file] = filepos;
@@ -242,9 +242,9 @@ void BookmarksSection::read(istream & is
itmp >> pos;
itmp.ignore(2); // ignore ", "
getline(itmp, fname);
- FileName const file(fname);
- if (!file.isAbsolute())
+ if (!FileName::isAbsolute(fname))
continue;
+ FileName const file(fname);
// only load valid bookmarks
if (file.exists() && !file.isDirectory() && idx <=
max_bookmarks)
bookmarks[idx] = Bookmark(file, pit, pos, 0, 0);
Index: src/support/os_cygwin.cpp
===================================================================
--- src/support/os_cygwin.cpp (Revision 28885)
+++ src/support/os_cygwin.cpp (Arbeitskopie)
@@ -195,7 +195,7 @@ string latex_path(string const & p)
// on windows_style_tex_paths_), but we use always forward slashes,
// since it gets written into a .tex file.
- if (windows_style_tex_paths_ && FileName(p).isAbsolute()) {
+ if (windows_style_tex_paths_ && FileName::isAbsolute(p)) {
string dos_path = convert_path(p, PathStyle(windows));
LYXERR(Debug::LATEX, "<Path correction for LaTeX> ["
<< p << "]->>[" << dos_path << ']');
Index: src/support/FileName.cpp
===================================================================
--- src/support/FileName.cpp (Revision 28885)
+++ src/support/FileName.cpp (Arbeitskopie)
@@ -105,6 +105,7 @@ struct FileName::Private
Private(string const & abs_filename) : fi(toqstr(abs_filename))
{
+ name = abs_filename;
fi.setCaching(fi.exists() ? true : false);
}
///
@@ -129,6 +130,8 @@ struct FileName::Private
Qt::CaseSensitive : Qt::CaseInsensitive) == 0;
}
+ /// The absolute file name in UTF-8 encoding.
+ std::string name;
///
QFileInfo fi;
};
@@ -148,6 +151,8 @@ FileName::FileName() : d(new Private)
FileName::FileName(string const & abs_filename)
: d(abs_filename.empty() ? new Private : new Private(abs_filename))
{
+ //LYXERR(Debug::FILES, "FileName(" << abs_filename << ')');
+ LASSERT(empty() || isAbsolute(d->name), /**/);
}
@@ -159,6 +164,7 @@ FileName::~FileName()
FileName::FileName(FileName const & rhs) : d(new Private)
{
+ d->name = rhs.d->name;
d->fi = rhs.d->fi;
}
@@ -171,6 +177,9 @@ FileName::FileName(FileName const & rhs,
FileName & FileName::operator=(FileName const & rhs)
{
+ if (&rhs == this)
+ return *this;
+ d->name = rhs.d->name;
d->fi = rhs.d->fi;
return *this;
}
@@ -178,39 +187,47 @@ FileName & FileName::operator=(FileName
bool FileName::empty() const
{
- return d->fi.absoluteFilePath().isEmpty();
+ return d->name.empty();
}
-bool FileName::isAbsolute() const
+bool FileName::isAbsolute(string const & name)
{
- return d->fi.isAbsolute();
+ QFileInfo fi(toqstr(name));
+ return fi.isAbsolute();
}
string FileName::absFilename() const
{
- return fromqstr(d->fi.absoluteFilePath());
+ return d->name;
}
void FileName::set(string const & name)
{
+ d->name = name;
d->fi.setFile(toqstr(name));
+ //LYXERR(Debug::FILES, "FileName::set(" << name << ')');
+ LASSERT(empty() || isAbsolute(d->name), /**/);
}
void FileName::set(FileName const & rhs, string const & suffix)
{
+ d->name = rhs.d->name + suffix;
if (!rhs.d->fi.isDir())
d->fi.setFile(rhs.d->fi.filePath() + toqstr(suffix));
else
d->fi.setFile(QDir(rhs.d->fi.absoluteFilePath()),
toqstr(suffix));
+ //LYXERR(Debug::FILES, "FileName::set(" << d->name << ')');
+ LASSERT(empty() || isAbsolute(d->name), /**/);
}
void FileName::erase()
{
+ d->name.clear();
d->fi = QFileInfo();
}
@@ -279,37 +296,39 @@ FileName FileName::fromFilesystemEncodin
bool FileName::exists() const
{
- return d->fi.exists();
+ return !empty() && d->fi.exists();
}
bool FileName::isSymLink() const
{
- return d->fi.isSymLink();
+ return !empty() && d->fi.isSymLink();
}
bool FileName::isFileEmpty() const
{
+ LASSERT(!empty(), return true);
return d->fi.size() == 0;
}
bool FileName::isDirectory() const
{
- return d->fi.isDir();
+ return !empty() && d->fi.isDir();
}
bool FileName::isReadOnly() const
{
+ LASSERT(!empty(), return true);
return d->fi.isReadable() && !d->fi.isWritable();
}
bool FileName::isReadableDirectory() const
{
- return d->fi.isDir() && d->fi.isReadable();
+ return isDirectory() && d->fi.isReadable();
}
@@ -340,26 +359,29 @@ bool FileName::hasExtension(const string
FileName FileName::onlyPath() const
{
FileName path;
+ if (empty())
+ return path;
path.d->fi.setFile(d->fi.path());
+ path.d->name = fromqstr(d->fi.absoluteFilePath());
return path;
}
bool FileName::isReadableFile() const
{
- return d->fi.isFile() && d->fi.isReadable();
+ return !empty() && d->fi.isFile() && d->fi.isReadable();
}
bool FileName::isWritable() const
{
- return d->fi.isWritable();
+ return !empty() && d->fi.isWritable();
}
bool FileName::isDirWritable() const
{
- LASSERT(d->fi.isDir(), return false);
+ LASSERT(isDirectory(), return false);
QFileInfo tmp(QDir(d->fi.absoluteFilePath()), "lyxwritetest");
QTemporaryFile qt_tmp(tmp.absoluteFilePath());
if (qt_tmp.open()) {
@@ -434,7 +456,9 @@ FileName FileName::tempName(string const
FileName FileName::getcwd()
{
- return FileName(".");
+ // return makeAbsPath("."); would create an infinite loop
+ QFileInfo fi(".");
+ return FileName(fromqstr(fi.absoluteFilePath()));
}
@@ -647,7 +671,7 @@ bool FileName::createDirectory(int permi
bool FileName::createPath() const
{
- LASSERT(!empty(), /**/);
+ LASSERT(!empty(), return false);
LYXERR(Debug::FILES, "creating path '" << *this << "'.");
if (isDirectory())
return false;
@@ -927,7 +951,7 @@ docstring const FileName::relPath(string
// see:
// http://www.qtsoftware.com/developer/task-tracker/
// index_html?id=248471&method=entry.
-bool operator==(FileName const & l, FileName const & r)
+bool equivalent(FileName const & l, FileName const & r)
{
// FIXME: In future use Qt.
// Qt 4.4: We need to solve this warning from Qt documentation:
@@ -967,6 +991,12 @@ bool operator==(FileName const & l, File
}
+bool operator==(FileName const & lhs, FileName const & rhs)
+{
+ return lhs.absFilename() == rhs.absFilename();
+}
+
+
bool operator!=(FileName const & lhs, FileName const & rhs)
{
return !(operator==(lhs, rhs));
@@ -1015,10 +1045,10 @@ DocFileName::DocFileName(FileName const
void DocFileName::set(string const & name, string const & buffer_path)
{
- FileName::set(name);
- bool const nameIsAbsolute = isAbsolute();
- save_abs_path_ = nameIsAbsolute;
- if (!nameIsAbsolute)
+ save_abs_path_ = isAbsolute(name);
+ if (save_abs_path_)
+ FileName::set(name);
+ else
FileName::set(makeAbsPath(name, buffer_path).absFilename());
zipped_valid_ = false;
}
Index: src/support/filetools.cpp
===================================================================
--- src/support/filetools.cpp (Revision 28885)
+++ src/support/filetools.cpp (Arbeitskopie)
@@ -375,10 +375,9 @@ string const onlyPath(string const & fil
// FIXME It might be nice if the code didn't simply assume that.
FileName const makeAbsPath(string const & relPath, string const & basePath)
{
- FileName relative_path(relPath);
// checks for already absolute path
- if (relative_path.isAbsolute())
- return relative_path;
+ if (FileName::isAbsolute(relPath))
+ return FileName(relPath);
// Copies given paths
string tempRel = os::internal_path(relPath);
@@ -387,8 +386,7 @@ FileName const makeAbsPath(string const
string tempBase;
- FileName base_path(basePath);
- if (base_path.isAbsolute())
+ if (FileName::isAbsolute(basePath))
tempBase = basePath;
else
tempBase = addPath(FileName::getcwd().absFilename(), basePath);
@@ -488,8 +486,7 @@ string const expandPath(string const & p
{
// checks for already absolute path
string rTemp = replaceEnvironmentPath(path);
- FileName abs_path(rTemp);
- if (abs_path.isAbsolute())
+ if (FileName::isAbsolute(rTemp))
return rTemp;
string temp;
Index: src/support/FileName.h
===================================================================
--- src/support/FileName.h (Revision 28885)
+++ src/support/FileName.h (Arbeitskopie)
@@ -60,7 +60,7 @@ public:
/// Is this filename empty?
bool empty() const;
/// Is the filename absolute?
- bool isAbsolute() const;
+ static bool isAbsolute(std::string const & name);
/// get the absolute file name in UTF-8 encoding
std::string absFilename() const;
@@ -191,13 +191,14 @@ public:
docstring const absoluteFilePath() const;
private:
- friend bool operator==(FileName const &, FileName const &);
+ friend bool equivalent(FileName const &, FileName const &);
///
struct Private;
Private * const d;
};
+bool equivalent(FileName const &, FileName const &);
bool operator==(FileName const &, FileName const &);
bool operator!=(FileName const &, FileName const &);
bool operator<(FileName const &, FileName const &);
Index: src/support/os_win32.cpp
===================================================================
--- src/support/os_win32.cpp (Revision 28885)
+++ src/support/os_win32.cpp (Arbeitskopie)
@@ -252,8 +252,7 @@ string latex_path(string const & p)
// on windows_style_tex_paths_), but we use always forward slashes,
// since it gets written into a .tex file.
- FileName path(p);
- if (!windows_style_tex_paths_ && path.isAbsolute()) {
+ if (!windows_style_tex_paths_ && FileName::isAbsolute(p)) {
string const drive = p.substr(0, 2);
string const cygprefix = cygdrive + "/" + drive.substr(0, 1);
string const cygpath = subst(subst(p, '\\', '/'), drive,
cygprefix);
Index: src/support/Package.cpp
===================================================================
--- src/support/Package.cpp (Revision 28885)
+++ src/support/Package.cpp (Arbeitskopie)
@@ -374,8 +374,7 @@ FileName const abs_path_from_command_lin
return FileName();
string const str_path = fix_dir_name(command_line);
- FileName path(str_path);
- return path.isAbsolute() ? path : makeAbsPath(str_path);
+ return makeAbsPath(str_path);
}
@@ -392,9 +391,8 @@ FileName const get_binary_path(string co
#else
string const exe_path = os::internal_path(exe);
#endif
- FileName exepath(exe_path);
- if (exepath.isAbsolute())
- return exepath;
+ if (FileName::isAbsolute(exe_path))
+ return FileName(exe_path);
// Two possibilities present themselves.
// 1. The binary is relative to the CWD.
Index: src/BufferList.cpp
===================================================================
--- src/BufferList.cpp (Revision 28885)
+++ src/BufferList.cpp (Arbeitskopie)
@@ -300,10 +300,25 @@ bool BufferList::isLoaded(Buffer const *
}
+namespace {
+struct equivalent_to : public binary_function<FileName, FileName, bool>
+{
+ bool operator()(FileName const & x, FileName const & y) const
+ { return equivalent(x, y); }
+};
+}
+
+
Buffer * BufferList::getBuffer(support::FileName const & fname) const
{
+ // 1) cheap test, using string comparison of file names
BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(),
bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
+ if (it != bstore.end())
+ return *it;
+ // 2) possibly expensive test, using quivalence test of file names
+ it = find_if(bstore.begin(), bstore.end(),
+ bind(equivalent_to(), bind(&Buffer::fileName, _1), fname));
return it != bstore.end() ? (*it) : 0;
}
Index: src/tex2lyx/text.cpp
===================================================================
--- src/tex2lyx/text.cpp (Revision 28885)
+++ src/tex2lyx/text.cpp (Arbeitskopie)
@@ -1049,8 +1049,7 @@ string const normalize_filename(string c
/// convention (relative to .lyx file) if it is relative
void fix_relative_filename(string & name)
{
- FileName fname(name);
- if (fname.isAbsolute())
+ if (FileName::isAbsolute(name))
return;
name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name,
getMasterFilePath()).absFilename()),