dmlite  0.6
Catalog.h
Go to the documentation of this file.
1 /// @file core/builtin/Catalog.h
2 /// @brief Implementation of a Catalog using other plugins, as INode.
3 /// @details Intended to ease the development of database backends.
4 /// @author Alejandro Álvarez Ayllon <aalvarez@cern.ch>
5 #ifndef BUILTIN_CATALOG_H
6 #define BUILTIN_CATALOG_H
7 
8 #include <dmlite/cpp/catalog.h>
9 #include <dmlite/cpp/inode.h>
10 #include <dmlite/cpp/poolmanager.h>
11 #include <dmlite/cpp/pooldriver.h>
12 
13 namespace dmlite {
14 
15  struct BuiltInDir: public Directory {
16  virtual ~BuiltInDir() {};
19  };
20 
21  class BuiltInCatalog: public Catalog {
22  public:
23  BuiltInCatalog(bool updateATime, unsigned symLinkLimit) throw (DmException);
25 
26  std::string getImplId(void) const throw();
27 
28  void setStackInstance(StackInstance* si) throw (DmException);
29 
30  void setSecurityContext(const SecurityContext*) throw (DmException);
31 
32  void changeDir (const std::string&) throw (DmException);
33  std::string getWorkingDir (void) throw (DmException);
34 
35  ExtendedStat extendedStat(const std::string& path,
36  bool followSym = true) throw (DmException);
37  ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException);
38 
39  bool access(const std::string& path, int mode) throw (DmException);
40  bool accessReplica(const std::string& replica, int mode) throw (DmException);
41 
42  void addReplica (const Replica& replica) throw (DmException);
43  void deleteReplica(const Replica& replica) throw (DmException);
44 
45  std::vector<Replica> getReplicas(const std::string& path) throw (DmException);
46  Location get(const std::string& path) throw (DmException);
47 
48  Location put(const std::string& path) throw (DmException);
49  void putDone(const std::string& host, const std::string& rfn,
50  const std::map<std::string, std::string>& params) throw (DmException);
51 
52  void symlink(const std::string& oldpath,
53  const std::string& newpath) throw (DmException);
54  std::string readLink(const std::string& path) throw (DmException);
55 
56  void unlink(const std::string& path) throw (DmException);
57 
58  void create(const std::string& path, mode_t mode) throw (DmException);
59 
60  void makeDir (const std::string& path, mode_t mode) throw (DmException);
61  void removeDir(const std::string& path) throw (DmException);
62 
63  void rename(const std::string& oldPath,
64  const std::string& newPath) throw (DmException);
65 
66  mode_t umask(mode_t mask) throw ();
67 
68  void setMode (const std::string& path, mode_t mode) throw (DmException);
69  void setOwner (const std::string& path, uid_t newUid, gid_t newGid,
70  bool followSymLink = true) throw (DmException);
71 
72  void setSize (const std::string& path, size_t newSize) throw (DmException);
73 
74  void setAcl(const std::string& path, const Acl& acls) throw (DmException);
75 
76  void utime(const std::string& path, const struct utimbuf* buf) throw (DmException);
77 
78  std::string getComment(const std::string& path) throw (DmException);
79  void setComment(const std::string& path,
80  const std::string& comment) throw (DmException);
81 
82  void setGuid(const std::string& path,
83  const std::string &guid) throw (DmException);
84 
85  void updateExtendedAttributes(const std::string& path,
86  const Extensible& attr) throw (DmException);
87 
88  Directory* openDir (const std::string& path) throw (DmException);
89  void closeDir(Directory* dir) throw (DmException);
90  struct dirent* readDir (Directory* dir) throw (DmException);
92 
93  Replica getReplicaByRFN(const std::string& rfn) throw (DmException);
94  void updateReplica(const Replica& replica) throw (DmException);
95 
96  protected:
97  /// Get the parent of a directory.
98  /// @param path The path to split.
99  /// @param parentPath Where to put the parent path.
100  /// @param name Where to put the file name (stripping last /).
101  /// @return The parent metadata.
102  ExtendedStat getParent(const std::string& path, std::string* parentPath,
103  std::string* name) throw (DmException);
104 
105  /// Update access time (if updateATime is true)
106  void updateAccessTime(const ExtendedStat& meta) throw (DmException);
107 
108  /// Traverse backwards to check permissions.
109  /// @param meta The file at the end
110  /// @note Throws an exception if it is not possible.
111  void traverseBackwards(const ExtendedStat& meta) throw (DmException);
112 
113  /// addFileSizeToParents
114  /// Add (or subtract) the size of the given file from
115  /// all its parent directories
116  /// @param fname The logical file name (SFN) of the file in question
117  /// @param subtract If true then subtract instead of adding
118  void addFileSizeToParents(const std::string &fname, bool subtract) throw (DmException);
119 
120  /// addFileSizeToParents
121  /// Add (or subtract) the size of the given file from
122  /// all its parent directories
123  /// @param st The stat information about the file in question
124  /// @param subtract If true then subtract instead of adding
125  void addFileSizeToParents(const ExtendedStat &statinfo, bool subtract) throw (DmException);
126 
127  private:
129 
131 
132  std::string cwdPath_;
133  ino_t cwd_;
134 
135  mode_t umask_;
137  unsigned symLinkLimit_;
138  };
139 
140  /// Plug-ins must implement a concrete factory to be instantiated.
142  public:
145 
146  void configure(const std::string&, const std::string&) throw (DmException);
147 
149 
150  private:
152  unsigned symLinkLimit_;
153  };
154 
155 };
156 
157 #endif // BUILTIN_CATALOG_H
BuiltInCatalog(bool updateATime, unsigned symLinkLimit)
void updateReplica(const Replica &replica)
std::string readLink(const std::string &path)
File/directory metadata.
Definition: inode.h:28
struct dirent * readDir(Directory *dir)
mode_t umask(mode_t mask)
void putDone(const std::string &host, const std::string &rfn, const std::map< std::string, std::string > &params)
unsigned symLinkLimit_
Definition: Catalog.h:137
Definition: security.h:51
void symlink(const std::string &oldpath, const std::string &newpath)
void closeDir(Directory *dir)
Plug-ins must implement a concrete factory to be instantiated.
Definition: catalog.h:216
Directory * openDir(const std::string &path)
bool accessReplica(const std::string &replica, int mode)
void updateAccessTime(const ExtendedStat &meta)
Update access time (if updateATime is true)
void rename(const std::string &oldPath, const std::string &newPath)
virtual ~BuiltInDir()
Definition: Catalog.h:16
Definition: dmlite.h:161
void setOwner(const std::string &path, uid_t newUid, gid_t newGid, bool followSymLink=true)
std::string getComment(const std::string &path)
Security context. To be created by the Authn.
Definition: authn.h:64
void utime(const std::string &path, const struct utimbuf *buf)
void setComment(const std::string &path, const std::string &comment)
Represent the complete location of a file.
Definition: pooldriver.h:42
Base exception class.
Definition: exceptions.h:17
File replica metadata.
Definition: inode.h:87
Plug-ins must implement a concrete factory to be instantiated.
Definition: Catalog.h:141
Definition: Catalog.h:21
CatalogInterface can only be instantiated through this class.
Definition: dmlite.h:42
void addFileSizeToParents(const std::string &fname, bool subtract)
Interface for Catalog (Namespaces).
Definition: catalog.h:29
ino_t cwd_
Definition: Catalog.h:133
bool updateATime_
Definition: Catalog.h:151
void traverseBackwards(const ExtendedStat &meta)
IDirectory * idir
Definition: Catalog.h:16
Pool API.
std::string getWorkingDir(void)
ExtendedStat extendedStat(const std::string &path, bool followSym=true)
bool access(const std::string &path, int mode)
Replica getReplicaByRFN(const std::string &rfn)
unsigned symLinkLimit_
Definition: Catalog.h:152
ExtendedStat extendedStatByRFN(const std::string &rfn)
Catalog API.
Helpful typedef for KeyValue containers.
Definition: extensible.h:20
void changeDir(const std::string &)
void removeDir(const std::string &path)
bool updateATime_
Definition: Catalog.h:136
Definition: Catalog.h:15
std::string getImplId(void) const
String ID of the implementation.
void makeDir(const std::string &path, mode_t mode)
std::string cwdPath_
Definition: Catalog.h:132
Location put(const std::string &path)
mode_t umask_
Definition: Catalog.h:135
void setGuid(const std::string &path, const std::string &guid)
const SecurityContext * secCtx_
Definition: Catalog.h:130
void updateExtendedAttributes(const std::string &path, const Extensible &attr)
void configure(const std::string &, const std::string &)
void unlink(const std::string &path)
void create(const std::string &path, mode_t mode)
ExtendedStat * readDirx(Directory *dir)
void setSecurityContext(const SecurityContext *)
Set the security context.
std::vector< Replica > getReplicas(const std::string &path)
void setAcl(const std::string &path, const Acl &acls)
ExtendedStat getParent(const std::string &path, std::string *parentPath, std::string *name)
void setSize(const std::string &path, size_t newSize)
void setMode(const std::string &path, mode_t mode)
void addReplica(const Replica &replica)
void deleteReplica(const Replica &replica)
StackInstance * si_
Definition: Catalog.h:128
Catalog * createCatalog(PluginManager *)
Instantiate a implementation of Catalog.
Low-level access API.
void setStackInstance(StackInstance *si)
ExtendedStat dir
Definition: Catalog.h:18
Pool handling API.
Typedef for directories.
Definition: inode.h:25
Typedef for directories.
Definition: catalog.h:26