]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileInfo.C
tostr -> convert and some bformat work
[lyx.git] / src / support / FileInfo.C
index 99825685f0e36435e0e859c05abe1a94a6fac422..0ac92ed87adfe9a9716b3baa0e23a7799eabb3f4 100644 (file)
 #include <config.h>
 
 #include "support/FileInfo.h"
+#include "support/lstrings.h"
 
 #include <boost/assert.hpp>
 
 #include <cerrno>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 
 using std::string;
@@ -141,7 +144,6 @@ char typeLetter(mode_t i)
        return '?';
 }
 
-
 } // namespace anon
 
 
@@ -155,7 +157,9 @@ FileInfo::FileInfo()
 
 
 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();
        dostat(link);
@@ -180,10 +184,15 @@ void FileInfo::init()
 
 void FileInfo::dostat(bool link)
 {
+#ifdef HAVE_LSTAT
        if (link)
                status_ = ::lstat(fname_.c_str(), &buf_);
        else
                status_ = ::stat(fname_.c_str(), &buf_);
+#else
+       status_ = ::stat(fname_.c_str(), &buf_);
+#endif
+
        if (status_)
                err_ = errno;
 }
@@ -191,7 +200,9 @@ void FileInfo::dostat(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;
        err_    = NoErr;
        dostat(link);
@@ -228,8 +239,6 @@ char FileInfo::typeIndicator() const
        if (S_ISSOCK(buf_.st_mode))
                return '=';
 #endif
-       if (S_ISREG(buf_.st_mode) && (buf_.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH)))
-               return '*';
        return ' ';
 }
 
@@ -314,7 +323,11 @@ bool FileInfo::isOK() const
 bool FileInfo::isLink() const
 {
        BOOST_ASSERT(isOK());
+#ifdef S_ISLNK
        return S_ISLNK(buf_.st_mode);
+#else
+       return false;
+#endif
 }