dmlite  0.6
src/core/builtin/Catalog.h
Go to the documentation of this file.
00001 /// @file    core/builtin/Catalog.h
00002 /// @brief   Implementation of a Catalog using other plugins, as INode.
00003 /// @details Intended to ease the development of database backends.
00004 /// @author  Alejandro Álvarez Ayllon <aalvarez@cern.ch>
00005 #ifndef BUILTIN_CATALOG_H
00006 #define BUILTIN_CATALOG_H
00007 
00008 #include <dmlite/cpp/catalog.h>
00009 #include <dmlite/cpp/inode.h>
00010 #include <dmlite/cpp/poolmanager.h>
00011 #include <dmlite/cpp/pooldriver.h>
00012 
00013 namespace dmlite {
00014   
00015   struct BuiltInDir: public Directory {
00016     virtual ~BuiltInDir() {};
00017     IDirectory*  idir;
00018     ExtendedStat dir;
00019   };
00020 
00021   class BuiltInCatalog: public Catalog {
00022    public:
00023     BuiltInCatalog(bool updateATime, unsigned symLinkLimit) throw (DmException);
00024     ~BuiltInCatalog();
00025 
00026     std::string getImplId(void) const throw();
00027 
00028     void setStackInstance(StackInstance* si) throw (DmException);
00029 
00030     void setSecurityContext(const SecurityContext*) throw (DmException);  
00031 
00032     void        changeDir     (const std::string&) throw (DmException);
00033     std::string getWorkingDir (void) throw (DmException);
00034 
00035     ExtendedStat extendedStat(const std::string& path,
00036                               bool followSym = true) throw (DmException);
00037     ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException);
00038 
00039     bool access(const std::string& path, int mode) throw (DmException);
00040     bool accessReplica(const std::string& replica, int mode) throw (DmException);
00041 
00042     void addReplica   (const Replica& replica) throw (DmException);
00043     void deleteReplica(const Replica& replica) throw (DmException);
00044 
00045     std::vector<Replica> getReplicas(const std::string& path) throw (DmException);
00046     Location get(const std::string& path) throw (DmException);
00047 
00048     Location put(const std::string& path) throw (DmException);
00049     void     putDone(const std::string& host, const std::string& rfn,
00050                     const std::map<std::string, std::string>& params) throw (DmException);
00051 
00052     void symlink(const std::string& oldpath,
00053                  const std::string& newpath) throw (DmException);
00054     std::string readLink(const std::string& path) throw (DmException);
00055 
00056     void unlink(const std::string& path) throw (DmException);
00057 
00058     void create(const std::string& path, mode_t mode) throw (DmException);
00059 
00060     void makeDir  (const std::string& path, mode_t mode) throw (DmException);
00061     void removeDir(const std::string& path) throw (DmException);
00062 
00063     void rename(const std::string& oldPath,
00064                 const std::string& newPath) throw (DmException);
00065 
00066     mode_t umask(mode_t mask) throw ();
00067 
00068     void setMode     (const std::string& path, mode_t mode) throw (DmException);
00069     void setOwner    (const std::string& path, uid_t newUid, gid_t newGid,
00070                       bool followSymLink = true) throw (DmException);
00071 
00072     void setSize    (const std::string& path, size_t newSize) throw (DmException);
00073     void setChecksum(const std::string& path, const std::string& csumtype,
00074                      const std::string& csumvalue) throw (DmException);
00075 
00076     void setAcl(const std::string& path, const Acl& acls) throw (DmException);
00077 
00078     void utime(const std::string& path, const struct utimbuf* buf) throw (DmException);
00079 
00080     std::string getComment(const std::string& path) throw (DmException);
00081     void        setComment(const std::string& path,
00082                            const std::string& comment) throw (DmException);
00083 
00084     void setGuid(const std::string& path,
00085                  const std::string &guid) throw (DmException);
00086 
00087     void updateExtendedAttributes(const std::string& path,
00088                                   const Extensible& attr) throw (DmException);
00089 
00090     Directory*     openDir (const std::string& path) throw (DmException);
00091     void           closeDir(Directory* dir) throw (DmException);
00092     struct dirent* readDir (Directory* dir) throw (DmException);
00093     ExtendedStat*  readDirx(Directory* dir) throw (DmException);
00094 
00095     Replica getReplicaByRFN(const std::string& rfn) throw (DmException);
00096     void    updateReplica(const Replica& replica)   throw (DmException);
00097 
00098    protected:
00099     /// Get the parent of a directory.
00100     /// @param path       The path to split.
00101     /// @param parentPath Where to put the parent path.
00102     /// @param name       Where to put the file name (stripping last /).
00103     /// @return           The parent metadata.
00104     ExtendedStat getParent(const std::string& path, std::string* parentPath,
00105                           std::string* name) throw (DmException);
00106 
00107     /// Update access time (if updateATime is true)
00108     void updateAccessTime(const ExtendedStat& meta) throw (DmException);
00109 
00110     /// Traverse backwards to check permissions.
00111     /// @param meta The file at the end
00112     /// @note       Throws an exception if it is not possible.
00113     void traverseBackwards(const ExtendedStat& meta) throw (DmException);
00114 
00115    private:
00116     StackInstance*   si_;
00117 
00118     const SecurityContext* secCtx_;
00119 
00120     std::string cwdPath_;
00121     ino_t       cwd_;
00122 
00123     mode_t   umask_;
00124     bool     updateATime_;
00125     unsigned symLinkLimit_;
00126   };
00127 
00128   /// Plug-ins must implement a concrete factory to be instantiated.
00129   class BuiltInCatalogFactory: public CatalogFactory {
00130    public:
00131     BuiltInCatalogFactory();
00132     ~BuiltInCatalogFactory();
00133 
00134     void configure(const std::string&, const std::string&) throw (DmException);
00135 
00136     Catalog* createCatalog(PluginManager*) throw (DmException);
00137 
00138    private:
00139     bool     updateATime_;
00140     unsigned symLinkLimit_;
00141   };
00142   
00143 };
00144 
00145 #endif  // BUILTIN_CATALOG_H