commit d0146c8e826d899c6a279a8ffba9be48a0293caa
Author: Enrico Forestieri <[email protected]>
Date: Tue May 5 22:29:22 2015 +0200
Don't update paths of non-existing files
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index c313883..194cd9b 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -5023,17 +5023,21 @@ void Buffer::checkMasterBuffer()
}
-string Buffer::includedFilePath(string const & name) const
+string Buffer::includedFilePath(string const & name, string const & ext) const
{
- if (d->old_position.empty() || d->old_position == filePath())
+ bool isabsolute = FileName::isAbsolute(name);
+ // old_position already contains a trailing path separator
+ string const absname = isabsolute ? name : d->old_position + name;
+
+ if (d->old_position.empty() || d->old_position == filePath()
+ || !FileName(addExtension(absname, ext)).exists())
return name;
- if (FileName::isAbsolute(name))
+ if (isabsolute)
return to_utf8(makeRelPath(from_utf8(name),
from_utf8(filePath())));
- // old_position already contains a trailing path separator
- string const cleanpath = FileName(d->old_position + name).realPath();
- return to_utf8(makeRelPath(from_utf8(cleanpath),
from_utf8(filePath())));
+ return to_utf8(makeRelPath(from_utf8(FileName(absname).realPath()),
+ from_utf8(filePath())));
}
} // namespace lyx
diff --git a/src/Buffer.h b/src/Buffer.h
index 46075d7..ad0c2aa 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -713,11 +713,14 @@ public:
///
void checkMasterBuffer();
- /// If the document is being saved to a new location, return the
- /// updated path of an included file relative to the new buffer path
- /// if possible, otherwise return its absolute path.
+ /// If the document is being saved to a new location and the named file
+ /// exists at the old location, return its updated path relative to the
+ /// new buffer path if possible, otherwise return its absolute path.
/// In all other cases, this is a no-op and name is returned unchanged.
- std::string includedFilePath(std::string const & name) const;
+ /// If a non-empty ext is given, the existence of name.ext is checked
+ /// but the returned path will not contain this extension.
+ std::string includedFilePath(std::string const & name,
+ std::string const & ext = empty_string()) const;
/// compute statistics between \p from and \p to
/// \p from initial position
diff --git a/src/insets/InsetCommandParams.cpp
b/src/insets/InsetCommandParams.cpp
index 519e937..074bd3a 100644
--- a/src/insets/InsetCommandParams.cpp
+++ b/src/insets/InsetCommandParams.cpp
@@ -346,7 +346,7 @@ void InsetCommandParams::Write(ostream & os, Buffer const *
buffer) const
string newdata;
string bib = token(data, ',', i);
while (!bib.empty()) {
- bib = buffer->includedFilePath(bib);
+ bib = buffer->includedFilePath(bib,
"bib");
if (!newdata.empty())
newdata.append(1, ',');
newdata.append(bib);