- // the document directory
- string filepath = buf->filePath();
- string const sysdir = package().system_support().absFileName();
- if (prefixIs(filepath, sysdir))
- filepath.replace(0, sysdir.length(), "/systemlyxdir/");
- else if (!lyxrc.save_origin)
+ os << "\\save_transient_properties "
+ << convert<string>(save_transient_properties) << '\n';
+
+ // the document directory (must end with a path separator)
+ // realPath() is used to resolve symlinks, while addPath(..., "")
+ // ensures a trailing path separator.
+ string filepath = addPath(buf->fileName().onlyPath().realPath(), "");
+ string const sysdir = addPath(package().system_support().realPath(), "");
+ string const relpath =
+ to_utf8(makeRelPath(from_utf8(filepath), from_utf8(sysdir)));
+ if (!prefixIs(relpath, "../") && !FileName::isAbsolute(relpath))
+ filepath = addPath("/systemlyxdir", relpath);
+ else if (!save_transient_properties || !lyxrc.save_origin)