#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;
return '?';
}
-
} // namespace anon
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);
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;
}
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);
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 ' ';
}
}
-nlink_t FileInfo::getNumberOfLinks() const
-{
- BOOST_ASSERT(isOK());
- return buf_.st_nlink;
-}
-
-
uid_t FileInfo::getUid() const
{
BOOST_ASSERT(isOK());
bool FileInfo::isLink() const
{
BOOST_ASSERT(isOK());
+#ifdef S_ISLNK
return S_ISLNK(buf_.st_mode);
+#else
+ return false;
+#endif
}