commit 8a015fce2fb07fd91e9e7c01d258c0f3574f83e8
Author: Enrico Forestieri <[email protected]>
Date: Tue May 5 22:47:46 2015 +0200
Don't update paths of non-existing files
No status line needed as this is an amendment to [4543bf28/lyxgit].
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 52212e8..782cbad 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4950,17 +4950,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 e855c20..1c6e808 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -707,11 +707,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);