aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-07-17 14:23:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-07-17 14:24:36 +0200
commite3a55c39b6dd7a866aa1033203a1813e646f8c50 (patch)
tree8ed4414769c88b371aef975fb55c4baf07287712
parent0184c3182f3bdc83fd4dc6f10ed3609cca32990c (diff)
Fix stat/lstat type/ltype to be consistent, use correct *stat()
-rw-r--r--butl/filesystem4
-rw-r--r--butl/filesystem.cxx6
-rw-r--r--butl/filesystem.ixx10
-rw-r--r--tests/dir-iterator/driver.cxx6
4 files changed, 13 insertions, 13 deletions
diff --git a/butl/filesystem b/butl/filesystem
index 63b19ff..0a5d7eb 100644
--- a/butl/filesystem
+++ b/butl/filesystem
@@ -96,11 +96,11 @@ namespace butl
public:
typedef butl::path path_type;
+ // Symlink target type in case of the symlink, ltype() otherwise.
+ //
entry_type
type () const;
- // Symlink target type in case of the symlink, type() otherwise.
- //
entry_type
ltype () const;
diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx
index c65d591..2a1fad9 100644
--- a/butl/filesystem.cxx
+++ b/butl/filesystem.cxx
@@ -42,7 +42,7 @@ namespace butl
file_mtime (const path& p)
{
struct stat s;
- if (::lstat (p.string ().c_str (), &s) != 0)
+ if (::stat (p.string ().c_str (), &s) != 0)
{
if (errno == ENOENT || errno == ENOTDIR)
return timestamp_nonexistent;
@@ -61,7 +61,7 @@ namespace butl
dir_exists (const path& p)
{
struct stat s;
- if (::lstat (p.string ().c_str (), &s) != 0)
+ if (::stat (p.string ().c_str (), &s) != 0)
{
if (errno == ENOENT || errno == ENOTDIR)
return false;
@@ -76,7 +76,7 @@ namespace butl
file_exists (const path& p)
{
struct stat s;
- if (::lstat (p.string ().c_str (), &s) != 0)
+ if (::stat (p.string ().c_str (), &s) != 0)
{
if (errno == ENOENT || errno == ENOTDIR)
return false;
diff --git a/butl/filesystem.ixx b/butl/filesystem.ixx
index 7aa3622..2d2690f 100644
--- a/butl/filesystem.ixx
+++ b/butl/filesystem.ixx
@@ -9,16 +9,16 @@ namespace butl
inline entry_type dir_entry::
type () const
{
- return t_ != entry_type::unknown ? t_ : (t_ = type (false));
+ entry_type t (ltype ());
+ return t != entry_type::symlink
+ ? t
+ : lt_ != entry_type::unknown ? lt_ : (lt_ = type (true));
}
inline entry_type dir_entry::
ltype () const
{
- entry_type t (type ());
- return t != entry_type::symlink
- ? t
- : lt_ != entry_type::unknown ? lt_ : (lt_ = type (true));
+ return t_ != entry_type::unknown ? t_ : (t_ = type (false));
}
// dir_iterator
diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx
index 09a259f..cc1e7d6 100644
--- a/tests/dir-iterator/driver.cxx
+++ b/tests/dir-iterator/driver.cxx
@@ -37,10 +37,10 @@ main (int argc, const char* argv[])
{
for (const dir_entry& de: dir_iterator (dir_path (argv[1])))
{
- cerr << de.type () << " ";
+ cerr << de.ltype () << " ";
- if (de.type () == entry_type::symlink)
- cerr << de.ltype ();
+ if (de.ltype () == entry_type::symlink)
+ cerr << de.type ();
else
cerr << " ";