Use real path names for buffer lookup by name of temporary external files.

In case of path names for external files containing symbolic links the real path
and the logical path name may be different for the same file or directory.
LyX is using QDir::tempPath() to create the path name of the temporary directory.
The Qt implementation is free to return the logical or the real path name here and
it happens to be different for various platforms and versions.
The most stable and clean solution is to use the real path name consistently.
This commit is contained in:
Stephan Witt 2020-02-22 12:11:42 +01:00
parent ca7defab45
commit f2f861f017
4 changed files with 12 additions and 18 deletions

View File

@ -82,9 +82,7 @@ test -z "${LYXPIPE}" && {
} }
if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
file=$(echo "$1" | sed 's|^/private||') MAC_LYXPIPE_CONTENTS="LYXCMD:macdvix:server-goto-file-row:$1 $2"
MAC_LYXPIPE_CONTENTS="LYXCMD:macdvix:server-goto-file-row:$file $2"
# echo "$MAC_LYXPIPE_CONTENTS" # echo "$MAC_LYXPIPE_CONTENTS"
echo "$MAC_LYXPIPE_CONTENTS" > "${LYXPIPE}".in || { echo "Cannot write to lyxpipe." ; exit 2 ; } echo "$MAC_LYXPIPE_CONTENTS" > "${LYXPIPE}".in || { echo "Cannot write to lyxpipe." ; exit 2 ; }
while read line ; do while read line ; do

View File

@ -318,10 +318,11 @@ Buffer * BufferList::getBuffer(support::FileName const & fname, bool internal) c
} }
Buffer * BufferList::getBufferFromTmp(string const & s) Buffer * BufferList::getBufferFromTmp(string const & s, bool realpath)
{ {
for (Buffer * buf : bstore) { for (Buffer * buf : bstore) {
if (prefixIs(s, buf->temppath())) { string const temppath = realpath ? FileName(buf->temppath()).realPath() : buf->temppath();
if (prefixIs(s, temppath)) {
// check whether the filename matches the master // check whether the filename matches the master
string const master_name = buf->latexName(); string const master_name = buf->latexName();
if (suffixIs(s, master_name)) if (suffixIs(s, master_name))

View File

@ -100,8 +100,9 @@ public:
/// \return a pointer to the buffer with the given number /// \return a pointer to the buffer with the given number
Buffer * getBuffer(unsigned int); Buffer * getBuffer(unsigned int);
/// \return a pointer to the buffer whose temppath matches the given path /// \return a pointer to the buffer whose temppath matches the given \p path
Buffer * getBufferFromTmp(std::string const & path); /// If optional \p realpath is \c true the lookup is done with real path names
Buffer * getBufferFromTmp(std::string const & path, bool realpath = false);
/** returns a pointer to the buffer that follows argument in /** returns a pointer to the buffer that follows argument in
* buffer list. The buffer following the last in list is the * buffer list. The buffer following the last in list is the

View File

@ -3668,7 +3668,7 @@ bool GuiView::goToFileRow(string const & argument)
int row = -1; int row = -1;
size_t i = argument.find_last_of(' '); size_t i = argument.find_last_of(' ');
if (i != string::npos) { if (i != string::npos) {
file_name = os::internal_path(trim(argument.substr(0, i))); file_name = os::internal_path(FileName(trim(argument.substr(0, i))).realPath());
istringstream is(argument.substr(i + 1)); istringstream is(argument.substr(i + 1));
is >> row; is >> row;
if (is.fail()) if (is.fail())
@ -3679,20 +3679,14 @@ bool GuiView::goToFileRow(string const & argument)
return false; return false;
} }
Buffer * buf = 0; Buffer * buf = 0;
string const abstmp = package().temp_dir().absFileName();
string const realtmp = package().temp_dir().realPath(); string const realtmp = package().temp_dir().realPath();
// We have to use os::path_prefix_is() here, instead of // We have to use os::path_prefix_is() here, instead of
// simply prefixIs(), because the file name comes from // simply prefixIs(), because the file name comes from
// an external application and may need case adjustment. // an external application and may need case adjustment.
if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED) if (os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
|| os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) { buf = theBufferList().getBufferFromTmp(file_name, true);
// Needed by inverse dvi search. If it is a file LYXERR(Debug::FILES, "goToFileRow: buffer lookup for " << file_name
// in tmpdir, call the apropriated function. << (buf ? " success" : " failed"));
// If tmpdir is a symlink, we may have the real
// path passed back, so we correct for that.
if (!prefixIs(file_name, abstmp))
file_name = subst(file_name, realtmp, abstmp);
buf = theBufferList().getBufferFromTmp(file_name);
} else { } else {
// Must replace extension of the file to be .lyx // Must replace extension of the file to be .lyx
// and get full path // and get full path