]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/stat.cpp
Add move semantics to Variant
[libs/core.git] / source / fs / stat.cpp
index ccd344b875e809ecdbf3016e96d4576ab0c898dc..e296ead3816b9317ecd44f0bc82bf6fbd12cbbed 100644 (file)
@@ -1,74 +1,56 @@
-#ifdef WIN32
-#include <io.h>
-#endif
-#include <msp/core/systemerror.h>
 #include "path.h"
 #include "stat.h"
+#include "stat_private.h"
+
+using namespace std;
 
 namespace Msp {
 namespace FS {
 
-int stat(const Path &fn, struct stat &st)
-{
-       return ::stat(fn.str().c_str(), &st);
-}
-
-struct stat stat(const Path &fn)
-{
-       struct stat st;
-       if(stat(fn, st)==-1)
-               throw system_error("stat");
-       return st;
-}
+Stat::Stat(const Stat &other):
+       exists(other.exists),
+       type(other.type),
+       size(other.type),
+       alloc_size(other.alloc_size),
+       mtime(other.mtime),
+       owner_info(other.owner_info),
+       priv(other.priv ? new Private(*other.priv) : nullptr)
+{ }
 
-int lstat(const Path &fn, struct stat &st)
+Stat &Stat::operator=(const Stat &other)
 {
-#ifdef WIN32
-       return stat(fn, st);
-#else
-       return ::lstat(fn.str().c_str(), &st);
-#endif
-}
+       if(&other==this)
+               return *this;
 
-struct stat lstat(const Path &fn)
-{
-       struct stat st;
-       if(lstat(fn, st)==-1)
-               throw system_error("lstat");
-       return st;
-}
+       exists = other.exists;
+       type = other.type;
+       size = other.size;
+       alloc_size = other.alloc_size;
+       mtime = other.mtime;
+       owner_info = other.owner_info;
+       delete priv;
+       priv = (other.priv ? new Private(*other.priv) : nullptr);
 
-bool exists(const Path &path)
-{
-       return access(path.str().c_str(), F_OK)==0;
+       return *this;
 }
 
-bool is_reg(const Path &path)
+Stat::~Stat()
 {
-       struct stat st;
-       if(stat(path, st)==0)
-               return S_ISREG(st.st_mode);
-       return false;
+       delete priv;
 }
 
-bool is_dir(const Path &path)
+const string &Stat::get_owner() const
 {
-       struct stat st;
-       if(stat(path, st)==0)
-               return S_ISDIR(st.st_mode);
-       return false;
+       if(priv && owner_info.owner.empty())
+               priv->fill_owner_info(owner_info);
+       return owner_info.owner;
 }
 
-bool is_link(const Path &path)
+const string &Stat::get_group() const
 {
-#ifdef WIN32
-       (void)path;
-#else
-       struct stat st;
-       if(lstat(path, st)==0)
-               return S_ISLNK(st.st_mode);
-#endif
-       return false;
+       if(priv && owner_info.group.empty())
+               priv->fill_owner_info(owner_info);
+       return owner_info.group;
 }
 
 } // namespace FS