* 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()
{
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)
{
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
*/
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