added some more methods to FileSTat class
authorReinhard Pfau <Reinhard.Pfau@gmx.de>
Sun, 12 Apr 2009 23:23:33 +0000 (01:23 +0200)
committerReinhard Pfau <Reinhard.Pfau@gmx.de>
Sun, 12 Apr 2009 23:23:33 +0000 (01:23 +0200)
utils/asyncio_system_tools.cpp
utils/asyncio_system_tools.hpp

index 48efb53..277304c 100644 (file)
@@ -40,9 +40,10 @@ namespace Utils
  * implementation of FileStat
  */
 
-FileStat::FileStat( const std::string& path)
+FileStat::FileStat( const std::string& path, bool follow_symlinks)
 : m_path( path )
 , m_is_valid( false )
+, m_follow_symlinks( follow_symlinks )
 {
     refresh();
 }// end of FileStat::FileStat()
@@ -57,7 +58,9 @@ void FileStat::refresh()
 {
     struct stat file_stat[1];
 
-    int res= ::stat( m_path.c_str(), file_stat );
+    int res;
+
+    res= (m_follow_symlinks ? ::stat : ::lstat)( m_path.c_str(), file_stat );
 
     if (res)
     {
@@ -67,9 +70,16 @@ void FileStat::refresh()
 
     m_is_regular_file= S_ISREG(file_stat->st_mode);
     m_is_directory= S_ISDIR(file_stat->st_mode);
+    m_is_character_device= S_ISCHR(file_stat->st_mode);
+    m_is_block_device= S_ISBLK(file_stat->st_mode);
+    m_is_fifo= S_ISFIFO(file_stat->st_mode);
+    m_is_symbolic_link= S_ISLNK(file_stat->st_mode);
+    m_is_socket= S_ISSOCK(file_stat->st_mode);
     // TODO: implement more!
 } // end of FileStat::refresh()
 
+
+
 /*
  * funcs
  */
index bad870e..1cf01a2 100644 (file)
@@ -37,37 +37,66 @@ namespace AsyncIo
 namespace Utils
 {
 
+/**
+ * @brief removed a file entry from file system (if existing).
+ * @param path path to be removed.
+ * @return @a true if the file was successfully deleted.
+ */
 bool unlink( const std::string& path );
 
 
+/**
+ * @brief represents a file(/path) status.
+ *
+ * This is basically a wrapper around the "stat" call.
+ */
 class FileStat
 {
     public:
-        FileStat( const std::string& path);
+        FileStat( const std::string& path, bool follow_symlinks= true );
         ~FileStat();
 
+        /**
+         * @brief stat the path again and updates the values.
+         */
         void refresh();
 
+        /**
+         * @brief returns if the stat values are valid.
+         * @return @a true if the stat values are valid.
+         */
         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; }
+        bool is_character_device() const { return m_is_character_device; }
+        bool is_block_device() const { return m_is_block_device; }
+        bool is_fifo() const { return m_is_fifo; }
+        bool is_symbolic_link() const { return m_is_symbolic_link; }
+        bool is_link() const { return m_is_symbolic_link; }
+        bool is_socket() const { return m_is_socket; }
 
     private:
         std::string m_path;
+        bool m_follow_symlinks;
 
         bool m_is_valid;
 
         bool m_is_regular_file;
         bool m_is_directory;
+        bool m_is_character_device;
+        bool m_is_block_device;
+        bool m_is_fifo;
+        bool m_is_symbolic_link;
+        bool m_is_socket;
 
 }; // end of FileStat
 
 
 } // end of namespace Utils
-}// end of namespace AsyncIo
+} // end of namespace AsyncIo
 
 
 #endif