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) ;
25 
26  std::string getImplId(void) const throw();
27 
29 
30  void setSecurityContext(const SecurityContext*) ;
31 
32  void changeDir (const std::string&) ;
33  std::string getWorkingDir (void) ;
34 
36  const std::string& path,
37  bool followSym) ;
38 
39  ExtendedStat extendedStat(const std::string& path,
40  bool followSym = true) ;
41  ExtendedStat extendedStatByRFN(const std::string& rfn) ;
42 
43 
44 
45  bool access(const std::string& path, int mode) ;
46  bool accessReplica(const std::string& replica, int mode) ;
47 
48  void addReplica (const Replica& replica) ;
49  void deleteReplica(const Replica& replica) ;
50 
51  std::vector<Replica> getReplicas(const std::string& path) ;
52  Location get(const std::string& path) ;
53 
54  Location put(const std::string& path) ;
55  void putDone(const std::string& host, const std::string& rfn,
56  const std::map<std::string, std::string>& params) ;
57 
58  void symlink(const std::string& oldpath,
59  const std::string& newpath) ;
60  std::string readLink(const std::string& path) ;
61 
62  void unlink(const std::string& path) ;
63 
64  void create(const std::string& path, mode_t mode) ;
65 
66  void makeDir (const std::string& path, mode_t mode) ;
67  void removeDir(const std::string& path) ;
68 
69  void rename(const std::string& oldPath,
70  const std::string& newPath) ;
71 
72  mode_t umask(mode_t mask);
73 
74  void setMode (const std::string& path, mode_t mode) ;
75  void setOwner (const std::string& path, uid_t newUid, gid_t newGid,
76  bool followSymLink = true) ;
77 
78  void setSize (const std::string& path, size_t newSize) ;
79 
80  void setAcl(const std::string& path, const Acl& acls) ;
81 
82  void utime(const std::string& path, const struct utimbuf* buf) ;
83 
84  std::string getComment(const std::string& path) ;
85  void setComment(const std::string& path,
86  const std::string& comment) ;
87 
88  void setGuid(const std::string& path,
89  const std::string &guid) ;
90 
91  void updateExtendedAttributes(const std::string& path,
92  const Extensible& attr) ;
93 
94  Directory* openDir (const std::string& path) ;
95  void closeDir(Directory* dir) ;
96  struct dirent* readDir (Directory* dir) ;
98 
99  Replica getReplicaByRFN(const std::string& rfn) ;
100  void updateReplica(const Replica& replica) ;
101 
102  protected:
103  /// Get the parent of a directory.
104  /// @param path The path to split.
105  /// @param parentPath Where to put the parent path.
106  /// @param name Where to put the file name (stripping last /).
107  /// @return The parent metadata.
108  ExtendedStat getParent(const std::string& path, std::string* parentPath,
109  std::string* name) ;
110 
111  /// Update access time (if updateATime is true)
112  void updateAccessTime(const ExtendedStat& meta) ;
113 
114  /// Traverse backwards to check permissions.
115  /// @param meta The file at the end
116  /// @note Throws an exception if it is not possible.
117  void traverseBackwards(const ExtendedStat& meta) ;
118 
119  /// addFileSizeToParents
120  /// Add (or subtract) the size of the given file from
121  /// all its parent directories
122  /// @param fname The logical file name (SFN) of the file in question
123  /// @param subtract If true then subtract instead of adding
124  void addFileSizeToParents(const std::string &fname, bool subtract) ;
125 
126  /// addFileSizeToParents
127  /// Add (or subtract) the size of the given file from
128  /// all its parent directories
129  /// @param st The stat information about the file in question
130  /// @param subtract If true then subtract instead of adding
131  void addFileSizeToParents(const ExtendedStat &statinfo, bool subtract) ;
132 
133  private:
135 
137 
138  std::string cwdPath_;
139  ino_t cwd_;
140 
141  mode_t umask_;
143  unsigned symLinkLimit_;
144  };
145 
146  /// Plug-ins must implement a concrete factory to be instantiated.
148  public:
151 
152  void configure(const std::string&, const std::string&) ;
153 
155 
156  private:
158  unsigned symLinkLimit_;
159  };
160 
161 };
162 
163 #endif // BUILTIN_CATALOG_H
BuiltInCatalog(bool updateATime, unsigned symLinkLimit)
void updateReplica(const Replica &replica)
Security context. To be created by the Authn.
Definition: authn.h:73
std::string readLink(const std::string &path)
struct dirent * readDir(Directory *dir)
mode_t umask(mode_t mask)
Represent the complete location of a file.
Definition: pooldriver.h:50
void putDone(const std::string &host, const std::string &rfn, const std::map< std::string, std::string > &params)
unsigned symLinkLimit_
Definition: Catalog.h:143
void symlink(const std::string &oldpath, const std::string &newpath)
void closeDir(Directory *dir)
Definition: status.h:17
Plug-ins must implement a concrete factory to be instantiated.
Definition: catalog.h:237
Directory * openDir(const std::string &path)
std::string getImplId(void) const
String ID of the implementation.
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)
void utime(const std::string &path, const struct utimbuf *buf)
void setComment(const std::string &path, const std::string &comment)
Plug-ins must implement a concrete factory to be instantiated.
Definition: Catalog.h:147
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:30
ino_t cwd_
Definition: Catalog.h:139
bool updateATime_
Definition: Catalog.h:157
void traverseBackwards(const ExtendedStat &meta)
IDirectory * idir
Definition: Catalog.h:16
Pool API.
std::string getWorkingDir(void)
bool access(const std::string &path, int mode)
Replica getReplicaByRFN(const std::string &rfn)
unsigned symLinkLimit_
Definition: Catalog.h:158
ExtendedStat extendedStatByRFN(const std::string &rfn)
void changeDir(const std::string &)
void removeDir(const std::string &path)
bool updateATime_
Definition: Catalog.h:142
Definition: Catalog.h:15
void makeDir(const std::string &path, mode_t mode)
std::string cwdPath_
Definition: Catalog.h:138
Location put(const std::string &path)
mode_t umask_
Definition: Catalog.h:141
void setGuid(const std::string &path, const std::string &guid)
File replica metadata.
Definition: inode.h:73
File/directory metadata.
Definition: inode.h:29
const SecurityContext * secCtx_
Definition: Catalog.h:136
void updateExtendedAttributes(const std::string &path, const Extensible &attr)
Helpful typedef for KeyValue containers.
Definition: extensible.h:20
Definition: security.h:52
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)
Namespace for the dmlite C++ API.
Definition: authn.h:16
StackInstance * si_
Definition: Catalog.h:134
Catalog * createCatalog(PluginManager *)
Instantiate a implementation of Catalog.
Low-level access API.
void setStackInstance(StackInstance *si)
ExtendedStat dir
Definition: Catalog.h:18
Catalog API.
Pool handling API.
Typedef for directories.
Definition: inode.h:26
DmStatus extendedStat(ExtendedStat &xstat, const std::string &path, bool followSym)
Typedef for directories.
Definition: catalog.h:27