From: Jean-Marc Lasgouttes Date: Wed, 17 Jul 2002 21:43:06 +0000 (+0000) Subject: fix startup when lyx binary is a symlink X-Git-Tag: 1.6.10~18824 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0e94da770a1f5cbd0aa54e894e871bdebcf1cd6f;p=features.git fix startup when lyx binary is a symlink git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4697 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 46ec5100d5..7b62ad35fe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2002-07-17 Jean-Marc Lasgouttes + + * lyx_main.C (init): make sure to read symlinks as absolute paths + 2002-07-17 John Levon * lyxfunc.h: diff --git a/src/lyx_main.C b/src/lyx_main.C index 0ac6fa81d7..3a0454692b 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -255,7 +255,7 @@ void LyX::init(bool gui) if (file.isLink()) { lyxerr[Debug::INIT] << "binary is a link" << endl; string link; - if (LyXReadLink(fullbinname, link)) { + if (LyXReadLink(fullbinname, link, true)) { // Path of binary/../share/name of binary/ searchpath += NormalizePath(AddPath(binpath, "../share/") @@ -279,7 +279,7 @@ void LyX::init(bool gui) lyxerr << " directory " << fullbinpath << " is a link" << endl; string link; - if (LyXReadLink(fullbinpath, link)) { + if (LyXReadLink(fullbinpath, link, true)) { fullbinpath = link; binpath = MakeAbsPath(OnlyPath(fullbinpath)); } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index eb4e94c52d..640e9b1150 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2002-07-17 Jean-Marc Lasgouttes + + * filetools.C (LyXReadLink): add bool 'resolve' to return link + contents as an absolute path + 2002-07-15 Jean-Marc Lasgouttes * filetools.C (IsLyXFilename): diff --git a/src/support/filetools.C b/src/support/filetools.C index 2e3ccac7b4..d45d317612 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1269,16 +1269,19 @@ MakeDisplayPath (string const & path, unsigned int threshold) } -bool LyXReadLink(string const & File, string & Link) +bool LyXReadLink(string const & file, string & link, bool resolve) { - char LinkBuffer[512]; + char linkbuffer[512]; // Should be PATH_MAX but that needs autconf support - int const nRead = ::readlink(File.c_str(), - LinkBuffer, sizeof(LinkBuffer) - 1); + int const nRead = ::readlink(file.c_str(), + linkbuffer, sizeof(linkbuffer) - 1); if (nRead <= 0) return false; - LinkBuffer[nRead] = '\0'; // terminator - Link = LinkBuffer; + linkbuffer[nRead] = '\0'; // terminator + if (resolve) + link = MakeAbsPath(linkbuffer, OnlyPath(file)); + else + link = linkbuffer; return true; } diff --git a/src/support/filetools.h b/src/support/filetools.h index 5b89d84eb9..bd15dfd3df 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -195,9 +195,10 @@ string const GetFileContents(string const & fname); */ string const ReplaceEnvironmentPath(string const & path); -/* Set Link to the path file points to as a symbolic link. +/* Set \c link to the path \c file points to as a symbolic link. + If \c resolve is true, then \c link is an absolute path Returns true if successful */ -bool LyXReadLink(string const & file, string & Link); +bool LyXReadLink(string const & file, string & link, bool resolve = false); /// Uses kpsewhich to find tex files string const findtexfile(string const & fil, string const & format);