]> git.lyx.org Git - features.git/commitdiff
Improve directory name juggling
authorGeorg Baum <baum@lyx.org>
Fri, 18 Dec 2015 19:20:04 +0000 (20:20 +0100)
committerGeorg Baum <baum@lyx.org>
Fri, 18 Dec 2015 19:20:04 +0000 (20:20 +0100)
The old code did not ensure that the path was only broken into parts at
directory separators. The new code ensures it.

src/BufferParams.cpp

index a5c3bfa2fc93f1ae2a0843d2e5fc08aaaa8e9508..e3121c77700dca202e75ba831f026c757d3eb01d 100644 (file)
@@ -1020,11 +1020,10 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
        // so we can catch also eventually used symbolic parts of the path.
        string filepath = buf->fileName().onlyPath().realPath();
        string const sysdir = package().system_support().realPath();
-       if (prefixIs(filepath, sysdir)) {
-               filepath.replace(0, sysdir.length(), "/systemlyxdir/");
-               // Remove eventually added superfluous "/"
-               filepath = subst(filepath, "//", "/");
-       }
+       string const relpath =
+               to_utf8(makeRelPath(from_utf8(filepath), from_utf8(sysdir)));
+       if (!prefixIs(relpath, "../") && !FileName::isAbsolute(relpath))
+               filepath = addPath("/systemlyxdir", relpath);
        else if (!lyxrc.save_origin)
                filepath = "unavailable";
        os << "\\origin " << quoteIfNeeded(filepath) << '\n';