Test for OS support for symbolic links and protect support library code

appropriately.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9421 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2005-01-04 13:24:56 +00:00
parent 835a97a293
commit 7b65e17539
3 changed files with 32 additions and 3 deletions

View File

@ -1,3 +1,13 @@
2005-01-04 Angus Leeming <leeming@lyx.org>
* FileInfo.C (FileInfo, newFile): strip the trailing '/' from
the stored file name as it breaks Window's version of stat().
(isLink): protect the code with #ifdef S_ISLNK.
(dostat): protect the code with #ifdef HAVE_LSTAT.
* filetools.C (LyXReadLink): protect the code with
#ifdef HAVE_READLINK.
2005-01-01 Kayvan Sylvan <kayvan@sylvan.com> 2005-01-01 Kayvan Sylvan <kayvan@sylvan.com>
* os_win32.C (internal_path): remove the call to MakeLatexName as * os_win32.C (internal_path): remove the call to MakeLatexName as

View File

@ -11,10 +11,13 @@
#include <config.h> #include <config.h>
#include "support/FileInfo.h" #include "support/FileInfo.h"
#include "support/lstrings.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <cerrno> #include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
using std::string; using std::string;
@ -141,7 +144,6 @@ char typeLetter(mode_t i)
return '?'; return '?';
} }
} // namespace anon } // namespace anon
@ -155,7 +157,9 @@ FileInfo::FileInfo()
FileInfo::FileInfo(string const & path, bool link) FileInfo::FileInfo(string const & path, bool link)
: fname_(path) // Win32 stat() doesn't dig trailing slashes.
// Posix stat() doesn't care, but we'll remove it anyway.
: fname_(rtrim(path, "/"))
{ {
init(); init();
dostat(link); dostat(link);
@ -180,10 +184,15 @@ void FileInfo::init()
void FileInfo::dostat(bool link) void FileInfo::dostat(bool link)
{ {
#ifdef HAVE_LSTAT
if (link) if (link)
status_ = ::lstat(fname_.c_str(), &buf_); status_ = ::lstat(fname_.c_str(), &buf_);
else else
status_ = ::stat(fname_.c_str(), &buf_); status_ = ::stat(fname_.c_str(), &buf_);
#else
status_ = ::stat(fname_.c_str(), &buf_);
#endif
if (status_) if (status_)
err_ = errno; err_ = errno;
} }
@ -191,7 +200,9 @@ void FileInfo::dostat(bool link)
FileInfo & FileInfo::newFile(string const & path, bool link) FileInfo & FileInfo::newFile(string const & path, bool link)
{ {
fname_ = path; // Win32 stat() doesn't dig trailing slashes.
// Posix stat() doesn't care, but we'll remove it anyway.
fname_ = rtrim(path, "/");
status_ = 0; status_ = 0;
err_ = NoErr; err_ = NoErr;
dostat(link); dostat(link);
@ -314,7 +325,11 @@ bool FileInfo::isOK() const
bool FileInfo::isLink() const bool FileInfo::isLink() const
{ {
BOOST_ASSERT(isOK()); BOOST_ASSERT(isOK());
#ifdef S_ISLNK
return S_ISLNK(buf_.st_mode); return S_ISLNK(buf_.st_mode);
#else
return false;
#endif
} }

View File

@ -1145,6 +1145,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
bool LyXReadLink(string const & file, string & link, bool resolve) bool LyXReadLink(string const & file, string & link, bool resolve)
{ {
#ifdef HAVE_READLINK
char linkbuffer[512]; char linkbuffer[512];
// Should be PATH_MAX but that needs autconf support // Should be PATH_MAX but that needs autconf support
int const nRead = ::readlink(file.c_str(), int const nRead = ::readlink(file.c_str(),
@ -1157,6 +1158,9 @@ bool LyXReadLink(string const & file, string & link, bool resolve)
else else
link = linkbuffer; link = linkbuffer;
return true; return true;
#else
return false;
#endif
} }