Refine tex2lyx -copyfiles logic.

Now all files are copied if the resulting path is valid.
Before the regressions tests would fail depending on the build directory
location.
This commit is contained in:
Georg Baum 2012-10-06 13:55:25 +02:00
parent 2801f40ad2
commit e119ba6094
2 changed files with 18 additions and 21 deletions

View File

@ -77,7 +77,7 @@ named \fIfoo.lyx.lyx\fR, and the re-exported file will be named
\fIfoo.lyx.tex\fR.
.TP
.BI \-copyfiles
Copy all included files below the input directory and that \fBtex2lyx\fR is
Copy all included files \fBtex2lyx\fR is
aware of to the output directory if the output file is located in a different
directory than the input file. This is useful if you want to ensure that no
included file is overwritten (either in roundtrip mode or by a later export

View File

@ -1836,28 +1836,31 @@ void fix_child_filename(string & name)
if (!isabs)
name = makeAbsPath(name, absMasterTeX).absFileName();
bool copyfile = copyFiles();
// convert from absolute original path to "relative to master file"
string const rel = to_utf8(makeRelPath(from_utf8(name),
from_utf8(absMasterTeX)));
// Do not copy if the file is not in or below the directory of the
// master, since in this case the new path might be impossible to
// create. Example:
// absMasterTeX = "/foo/bar/"
// absMasterLyX = "/bar/"
// name = "/baz.eps" => new absolute name would be "/../baz.eps"
if (copyfile && rel.substr(0, 3) == "../")
copyfile = false;
string const absParentLyX = getParentFilePath(false);
string abs = name;
if (copyfile) {
// convert from absolute original path to "relative to master file"
string const rel = to_utf8(makeRelPath(from_utf8(name),
from_utf8(absMasterTeX)));
// re-interpret "relative to .tex file" as "relative to .lyx file"
// (is different if the master .lyx file resides in a
// different path than the master .tex file)
string const absMasterLyX = getMasterFilePath(false);
name = makeAbsPath(rel, absMasterLyX).absFileName();
if (!isabs) {
abs = makeAbsPath(rel, absMasterLyX).absFileName();
// Do not copy if the new path is impossible to create. Example:
// absMasterTeX = "/foo/bar/"
// absMasterLyX = "/bar/"
// name = "/baz.eps" => new absolute name would be "/../baz.eps"
if (contains(name, "/../"))
copyfile = false;
}
if (copyfile) {
if (isabs)
name = abs;
else {
// convert from absolute original path to
// "relative to .lyx file"
name = to_utf8(makeRelPath(from_utf8(name),
name = to_utf8(makeRelPath(from_utf8(abs),
from_utf8(absParentLyX)));
}
}
@ -1880,12 +1883,6 @@ void copy_file(FileName const & src, string dstname)
else
dst = makeAbsPath(dstname, absParent);
string const absMaster = getMasterFilePath(false);
string const rel = to_utf8(makeRelPath(from_utf8(dst.absFileName()),
from_utf8(absMaster)));
// Do not copy if the file is not in or below the directory of the
// master (see above)
if (rel.substr(0, 3) == "../")
return;
FileName const srcpath = src.onlyPath();
FileName const dstpath = dst.onlyPath();
if (equivalent(srcpath, dstpath))