#include "asyncio_system_tools.hpp"
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
namespace AsyncIo
namespace Utils
{
- bool unlink( const std::string& path )
- {
+/*
+ * implementation of FileStat
+ */
+
+FileStat::FileStat( const std::string& path)
+: m_path( path )
+, m_is_valid( false )
+{
+ refresh();
+}// end of FileStat::FileStat()
+
+
+FileStat::~FileStat()
+{
+} // end of FileStat::~FileStat()
+
+
+void FileStat::refresh()
+{
+ struct stat file_stat[1];
+
+ int res= ::stat( m_path.c_str(), file_stat );
+
+ if (res)
+ {
+ m_is_valid= false;
+ return;
+ }
+
+ m_is_regular_file= S_ISREG(file_stat->st_mode);
+ m_is_directory= S_ISDIR(file_stat->st_mode);
+ // TODO: implement more!
+} // end of FileStat::refresh()
+
+/*
+ * funcs
+ */
+
+bool unlink( const std::string& path )
+{
return ::unlink( path.c_str() ) == 0;
- } // end of unlink(const std::string&)
+} // end of unlink(const std::string&)
+
+
} // end of namespace Utils
namespace Utils
{
- bool unlink( const std::string& path );
+bool unlink( const std::string& path );
+
+
+class FileStat
+{
+ public:
+ FileStat( const std::string& path);
+ ~FileStat();
+
+ void refresh();
+
+ bool is_valid() const { return m_is_valid; }
+
+ operator bool() const { return m_is_valid; }
+
+ bool is_regular_file() const { return m_is_regular_file; }
+ bool is_directory() const { return m_is_directory; }
+
+ private:
+ std::string m_path;
+
+ bool m_is_valid;
+
+ bool m_is_regular_file;
+ bool m_is_directory;
+
+}; // end of FileStat
+
} // end of namespace Utils
}// end of namespace AsyncIo