]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileInfo.C
tostr -> convert and some bformat work
[lyx.git] / src / support / FileInfo.C
index 1919c9c7025ed916c7d9e29f16062a0c3833c3c1..0ac92ed87adfe9a9716b3baa0e23a7799eabb3f4 100644 (file)
@@ -5,14 +5,23 @@
  *
  * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
+#include "support/FileInfo.h"
+#include "support/lstrings.h"
+
+#include <boost/assert.hpp>
+
 #include <cerrno>
-#include "FileInfo.h"
-#include "LAssert.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
+using std::string;
+
 
 #if !S_IRUSR
 # if S_IREAD
@@ -135,7 +144,6 @@ char typeLetter(mode_t i)
        return '?';
 }
 
-
 } // namespace anon
 
 
@@ -149,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);
@@ -174,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;
 }
@@ -185,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);
@@ -207,7 +224,7 @@ FileInfo & FileInfo::newFile(int fildes)
 // should not be in FileInfo
 char FileInfo::typeIndicator() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        if (S_ISDIR(buf_.st_mode))
                return '/';
 #ifdef S_ISLNK
@@ -222,15 +239,13 @@ 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 ' ';
 }
 
 
 mode_t FileInfo::getMode() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_mode;
 }
 
@@ -238,7 +253,7 @@ mode_t FileInfo::getMode() const
 // should not be in FileInfo
 string FileInfo::modeString() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        char str[11];
        str[0] = typeLetter(buf_.st_mode);
        flagRWX((buf_.st_mode & 0700) << 0, &str[1]);
@@ -253,49 +268,42 @@ string FileInfo::modeString() const
 
 time_t FileInfo::getModificationTime() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_mtime;
 }
 
 
 time_t FileInfo::getAccessTime() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_atime;
 }
 
 
 time_t FileInfo::getStatusChangeTime() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_ctime;
 }
 
 
-nlink_t FileInfo::getNumberOfLinks() const
-{
-       Assert(isOK());
-       return buf_.st_nlink;
-}
-
-
 uid_t FileInfo::getUid() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_uid;
 }
 
 
 gid_t FileInfo::getGid() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_gid;
 }
 
 
 off_t FileInfo::getSize() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return buf_.st_size;
 }
 
@@ -314,49 +322,53 @@ bool FileInfo::isOK() const
 
 bool FileInfo::isLink() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
+#ifdef S_ISLNK
        return S_ISLNK(buf_.st_mode);
+#else
+       return false;
+#endif
 }
 
 
 bool FileInfo::isRegular() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return S_ISREG(buf_.st_mode);
 }
 
 
 bool FileInfo::isDir() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return S_ISDIR(buf_.st_mode);
 }
 
 
 bool FileInfo::isChar() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return S_ISCHR(buf_.st_mode);
 }
 
 
 bool FileInfo::isBlock() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return S_ISBLK(buf_.st_mode);
 }
 
 
 bool FileInfo::isFifo() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
        return S_ISFIFO(buf_.st_mode);
 }
 
 
 bool FileInfo::isSocket() const
 {
-       Assert(isOK());
+       BOOST_ASSERT(isOK());
 #ifdef S_ISSOCK
        return S_ISSOCK(buf_.st_mode);
 #else