PathInfo.hpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                     _     _   _   _     __     _                     |
00004 |                    | |   | | | \_/ |   /  \   | |                    |
00005 |                    | |   | | | |_| |  / /\ \  | |                    |
00006 |                    | |__ | | | | | | / ____ \ | |__                  |
00007 |                    |____||_| |_| |_|/ /    \ \|____|                 |
00008 |                                                                      |
00009 |                             core library                             |
00010 |                                                                      |
00011 |                                         (C) SUSE Linux Products GmbH |
00012 \----------------------------------------------------------------------/
00013 
00014   File:       PathInfo.hpp
00015 
00016   Maintainer: Michael Calmer
00017 
00018 /----------------------------------------------------------------------\
00019 |                                                                      |
00020 |                      __   __    ____ _____ ____                      |
00021 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00022 |                       \ V / _` \___ \ | |   __) |                    |
00023 |                        | | (_| |___) || |  / __/                     |
00024 |                        |_|\__,_|____/ |_| |_____|                    |
00025 |                                                                      |
00026 |                               core system                            |
00027 |                                                        (C) SuSE GmbH |
00028 \----------------------------------------------------------------------/
00029 
00030    File:       PathInfo.h
00031 
00032    Author:     Michael Andres <ma@suse.de>
00033    Maintainer: Michael Andres <ma@suse.de>
00034 
00035 /-*/
00040 #ifndef LIMAL_PATH_PATHINFO_HPP
00041 #define LIMAL_PATH_PATHINFO_HPP
00042 
00043 #include <limal/config.h>
00044 #include <limal/PathName.hpp>
00045 #include <blocxx/Map.hpp>
00046 
00047 #include <cerrno>
00048 #include <iosfwd>
00049 #include <set>
00050 
00051 extern "C"
00052 {
00053 #include <sys/types.h>
00054 #include <sys/stat.h>
00055 #include <fcntl.h>
00056 #include <unistd.h>
00057 #include <dirent.h>
00058 }
00059 
00060 namespace LIMAL_NAMESPACE {
00061 
00062 namespace path {
00063 
00064 
00100 class PathInfo {
00101 
00102   public:
00103 
00104     enum Mode { E_STAT, E_LSTAT };
00105 
00106     enum FileType {
00107       NOT_AVAIL  = 0x00, 
00108       NOT_EXIST  = 0x01, 
00109       T_FILE     = 0x02, 
00110       T_DIR      = 0x04, 
00111       T_CHARDEV  = 0x08, 
00112       T_BLOCKDEV = 0x10, 
00113       T_FIFO     = 0x20, 
00114       T_LINK     = 0x40, 
00115       T_SOCKET   = 0x80  
00116     };
00117 
00133     friend std::ostream & operator<<( std::ostream & str, FileType obj );
00134     friend std::ostream & operator<<( std::ostream & str, const PathInfo &obj);
00135 
00136 
00140     class StatMode;
00141 
00146     class DevInoCache;
00147 
00148   private:
00149 
00150     PathName    m_path;
00151 
00152     struct stat m_statbuf_C;
00153     Mode        m_mode;
00154     int         m_error;
00155 
00156   public:
00157 
00158 
00166     PathInfo( const PathName & path = "", Mode initial = E_STAT );
00167 
00176     PathInfo( const blocxx::String & path, Mode initial = E_STAT );
00177 
00185     PathInfo( const char * path, Mode initial = E_STAT );
00186 
00190     virtual ~PathInfo();
00191     
00196     const PathName           path()     const { return m_path; }
00197 
00204     blocxx::String           toString() const { return m_path.toString(); }
00211     Mode                     mode()     const { return m_mode; }
00212 
00224     int                      error()    const { return m_error; }
00225 
00230     void                     setPath( const PathName & path );
00231 
00244     void                     setMode( Mode mode );
00245 
00246 
00259     bool                     stat   ( const PathName & path );
00260 
00273     bool                     lstat  ( const PathName & path );
00274 
00275 
00290     bool                     operator()( const PathName & path );
00291 
00292 
00303     bool                     stat();
00304     
00315     bool                     lstat();
00316 
00326     bool                     operator()();
00327 
00328 
00329 
00337     bool                     exists() const { return !m_error; }
00338 
00342     // @{ 
00349     FileType                 fileType() const;
00350 
00351 
00355     bool                     isFile()  const;
00356     
00360     bool                     isDir ()  const;
00361     
00365     bool                     isLink()  const;
00366     
00370     bool                     isChr()   const;
00371     
00375     bool                     isBlk()   const;
00376     
00380     bool                     isFifo()  const;
00381     
00385     bool                     isSock()  const;
00386 
00387     // @}
00388 
00395     nlink_t                  nlink()  const;
00396 
00404     uid_t                    owner()   const;
00405 
00413     gid_t                    group()   const;
00414 
00422     // @{
00424     bool                     isRUsr()  const;
00426     bool                     isWUsr()  const;
00428     bool                     isXUsr()  const;
00429  
00431     bool                     isR()     const;
00433     bool                     isW()     const;
00435     bool                     isX()     const;
00436 
00438     bool                     isRGrp()  const;
00440     bool                     isWGrp()  const;
00442     bool                     isXGrp()  const;
00443 
00445     bool                     isROth()  const;
00447     bool                     isWOth()  const;
00449     bool                     isXOth()  const;
00450 
00452     bool                     isUid()   const;
00454     bool                     isGid()   const;
00456     bool                     isVtx()   const;
00457 
00464     mode_t                   uperm()   const;
00465     
00472     mode_t                   gperm()   const;
00473     
00480     mode_t                   operm()   const;
00481 
00486     mode_t                   perm()    const;
00487 
00488 
00498     bool                     isPerm ( mode_t m ) const;
00499     
00509     bool                     hasPerm( mode_t m ) const;
00510 
00526     mode_t                   st_mode() const;
00527 
00533     mode_t                   userMay() const;
00534 
00535 
00542     bool                     userMayR() const;
00543     
00550     bool                     userMayW() const;
00551     
00558     bool                     userMayX() const;
00559 
00567     bool                     userMayRW()  const;
00568     
00576     bool                     userMayRX()  const;
00577    
00585     bool                     userMayWX()  const;
00586 
00594     bool                     userMayRWX() const;
00595  
00596     // @}
00597 
00598     // device
00599 
00605     dev_t                    dev()     const;
00606 
00612     dev_t                    rdev()    const;
00613 
00620     ino_t                    ino()     const;
00621 
00633     ::off_t                  size()    const;
00634 
00641     blksize_t                blksize() const;
00642 
00649     blkcnt_t                 blocks()  const;
00650 
00652     // @{
00658     time_t                   atime()   const; /* time of last access */
00659     
00665     time_t                   mtime()   const; /* time of last modification */
00666     
00672     time_t                   ctime()   const;
00673 
00674     // @}
00675 };
00676 
00678 
00684 class PathInfo::StatMode {
00685 
00686   friend std::ostream & operator<<( std::ostream & str, const PathInfo::StatMode & obj );
00687 
00688   private:
00689     mode_t _mode;
00690   public:
00691     StatMode( const mode_t & mode_r = 0 ) : _mode( mode_r ) {}
00692 
00700     // @{
00701     FileType fileType() const;
00702 
00703     bool     isFile()  const;
00704     bool     isDir ()  const;
00705     bool     isLink()  const;
00706     bool     isChr()   const;
00707     bool     isBlk()   const;
00708     bool     isFifo()  const;
00709     bool     isSock()  const;
00710     // @}
00711     
00713     // @{
00714     bool     isRUsr()  const;
00715     bool     isWUsr()  const;
00716     bool     isXUsr()  const;
00717 
00718     bool     isR()     const;
00719     bool     isW()     const;
00720     bool     isX()     const;
00721 
00722     bool     isRGrp()  const;
00723     bool     isWGrp()  const;
00724     bool     isXGrp()  const;
00725 
00726     bool     isROth()  const;
00727     bool     isWOth()  const;
00728     bool     isXOth()  const;
00729 
00730     bool     isUid()   const;
00731     bool     isGid()   const;
00732     bool     isVtx()   const;
00733 
00734     mode_t   uperm()   const;
00735     mode_t   gperm()   const;
00736     mode_t   operm()   const;
00737     mode_t   perm()    const;
00738 
00739     bool     isPerm( mode_t m ) const;
00740     bool     hasPerm( mode_t m ) const;
00741 
00742     mode_t   st_mode() const;
00743 
00744     // @}
00745 };
00746 
00748 
00763 class PathInfo::DevInoCache {
00764 
00765   private:
00766 
00767     blocxx::Map<dev_t,std::set<ino_t> > _devino;
00768 
00769   public:
00773     DevInoCache() {}
00774 
00778     void clear() { _devino.clear(); }
00779 
00788     bool insert( const dev_t & dev_r, const ino_t & ino_r ) {
00789       return _devino[dev_r].insert( ino_r ).second;
00790     }
00791 };
00792 
00794 
00796 
00797 }
00798 }
00799 
00800 #endif // LIMAL_PATH_PATHINFO_HPP

Generated on Tue May 2 09:52:00 2006 for limal by  doxygen 1.4.6