xrootd
Loading...
Searching...
No Matches
XrdOssCsiConfig.hh
Go to the documentation of this file.
1#ifndef _XRDOSSCSICONFIG_H
2#define _XRDOSSCSICONFIG_H
3/******************************************************************************/
4/* */
5/* X r d O s s C s i C o n f i g . h h */
6/* */
7/* (C) Copyright 2021 CERN. */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* In applying this licence, CERN does not waive the privileges and */
17/* immunities granted to it by virtue of its status as an Intergovernmental */
18/* Organization or submit itself to any jurisdiction. */
19/* */
20/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
21/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
22/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
23/* License for more details. */
24/* */
25/* You should have received a copy of the GNU Lesser General Public License */
26/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
27/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
28/* */
29/* The copyright holder's institutional names and contributor's names may not */
30/* be used to endorse or promote products derived from this software without */
31/* specific prior written permission of the institution or contributor. */
32/******************************************************************************/
33
34#include "XrdOss/XrdOss.hh"
36#include "XrdOuc/XrdOucEnv.hh"
38
39#include <string>
40
42{
43public:
44
45 TagPath() : prefix_("/.xrdt"), suffix_(".xrdt") { calcPrefixElements(); }
47
48 //
49 // path may be absolute or last element from a directory listing
50 bool isTagFile(const char *path)
51 {
52 if (!path || !*path) return false;
53 std::string s(path);
54 simplePath(s);
55 // if prefix_ set, the test is to match if "path" is equal to or a subpath of perfix_
56 if (!prefix_.empty())
57 {
58 if (s.find(prefix_) == 0)
59 {
60 if (prefix_.length() == s.length()) return true;
61 if (s[prefix_.length()] == '/') return true;
62 }
63 return false;
64 }
65 // prefix_ not set, test is if "path" ends with suffix_
66 const size_t haystack = s.length();
67 const size_t needle = suffix_.length();
68 if (haystack >= needle && s.substr(haystack-needle, std::string::npos) == suffix_) return true;
69 return false;
70 }
71
72 int SetPrefix(XrdSysError &Eroute, const std::string &v)
73 {
74 if (!v.empty() && v[0] != '/')
75 {
76 Eroute.Emsg("Config","prefix must be empty or start with /");
77 return 1;
78 }
79 prefix_ = v;
81 return XrdOssOK;
82 }
83
84 bool hasPrefix() { return !prefix_.empty(); }
85
86 //
87 // to convert an absolute data directory to corresponding tag directory
88 std::string makeBaseDirname(const char *path)
89 {
90 if (!path || *path != '/' || prefix_.empty()) return std::string();
91 std::string p(path);
92 simplePath(p);
93 if (p.length()>1) return prefix_ + p;
94 return prefix_;
95 }
96
97 //
98 // test if absolute path is the directory containing the
99 // base directory of the tags
100 bool matchPrefixDir(const char *path)
101 {
102 if (!path || *path != '/' || prefix_.empty()) return false;
103 std::string p(path);
104 simplePath(p);
105 if (prefixstart_ == p) return true;
106 return false;
107 }
108
109 // the name (not path) of directory containing the tags
110 std::string getPrefixName()
111 {
112 return prefixend_;
113 }
114
115 // take datafile name at absolute path and convert it to filename of tagfile
116 std::string makeTagFilename(const char *path)
117 {
118 if (!path || *path != '/') return std::string();
119 std::string p(path);
120 simplePath(p);
121 return prefix_ + p + suffix_;
122 }
123
124 std::string prefix_;
125
126private:
128 {
129 prefixstart_.clear();
130 prefixend_.clear();
131 if (prefix_.empty()) return;
133 const size_t idx = prefix_.rfind("/");
134 prefixstart_ = prefix_.substr(0,idx);
135 if (prefixstart_.empty()) prefixstart_ = std::string("/");
136 prefixend_ = prefix_.substr(idx+1,std::string::npos);
137 }
138
139 void simplePath(std::string &str)
140 {
141 // replace double slashes with single
142 size_t i=0;
143 do {
144 i = str.find("//", i);
145 if (i == std::string::npos) break;
146 str.erase(i, 1);
147 } while (!str.empty());
148
149 // remove trailing /
150 if (str.length()>1 && str[str.length()-1] == '/')
151 {
152 str.erase( str.end()-1 );
153 }
154 }
155
156 std::string prefixstart_;
157 std::string prefixend_;
158 std::string suffix_;
159};
160
162{
163public:
164
167
168 int Init(XrdSysError &, const char *, const char *, XrdOucEnv *);
169
170 bool fillFileHole() const { return fillFileHole_; }
171
172 std::string xrdtSpaceName() const { return xrdtSpaceName_; }
173
174 bool allowMissingTags() const { return allowMissingTags_; }
175
176 bool disablePgExtend() const { return disablePgExtend_; }
177
178 bool disableLooseWrite() const { return disableLooseWrite_; }
179
181
182private:
183 int readConfig(XrdSysError &, const char *);
184
186
188
190 std::string xrdtSpaceName_;
194};
195
196#endif
#define XrdOssOK
Definition XrdOss.hh:50
Definition XrdOssCsiConfig.hh:42
std::string getPrefixName()
Definition XrdOssCsiConfig.hh:110
void calcPrefixElements()
Definition XrdOssCsiConfig.hh:127
std::string prefixend_
Definition XrdOssCsiConfig.hh:157
void simplePath(std::string &str)
Definition XrdOssCsiConfig.hh:139
bool matchPrefixDir(const char *path)
Definition XrdOssCsiConfig.hh:100
std::string makeBaseDirname(const char *path)
Definition XrdOssCsiConfig.hh:88
std::string prefixstart_
Definition XrdOssCsiConfig.hh:156
std::string makeTagFilename(const char *path)
Definition XrdOssCsiConfig.hh:116
bool hasPrefix()
Definition XrdOssCsiConfig.hh:84
std::string suffix_
Definition XrdOssCsiConfig.hh:158
std::string prefix_
Definition XrdOssCsiConfig.hh:124
bool isTagFile(const char *path)
Definition XrdOssCsiConfig.hh:50
TagPath()
Definition XrdOssCsiConfig.hh:45
int SetPrefix(XrdSysError &Eroute, const std::string &v)
Definition XrdOssCsiConfig.hh:72
~TagPath()
Definition XrdOssCsiConfig.hh:46
Definition XrdOssCsiConfig.hh:162
bool fillFileHole() const
Definition XrdOssCsiConfig.hh:170
bool disablePgExtend_
Definition XrdOssCsiConfig.hh:192
std::string xrdtSpaceName_
Definition XrdOssCsiConfig.hh:190
std::string xrdtSpaceName() const
Definition XrdOssCsiConfig.hh:172
int xtrace(XrdOucStream &, XrdSysError &)
int Init(XrdSysError &, const char *, const char *, XrdOucEnv *)
int readConfig(XrdSysError &, const char *)
bool disableLooseWrite_
Definition XrdOssCsiConfig.hh:193
bool disableLooseWrite() const
Definition XrdOssCsiConfig.hh:178
~XrdOssCsiConfig()
Definition XrdOssCsiConfig.hh:166
int ConfigXeq(char *, XrdOucStream &, XrdSysError &)
bool disablePgExtend() const
Definition XrdOssCsiConfig.hh:176
bool allowMissingTags_
Definition XrdOssCsiConfig.hh:191
XrdOssCsiConfig()
Definition XrdOssCsiConfig.hh:165
bool fillFileHole_
Definition XrdOssCsiConfig.hh:189
TagPath tagParam_
Definition XrdOssCsiConfig.hh:180
bool allowMissingTags() const
Definition XrdOssCsiConfig.hh:174
Definition XrdOucEnv.hh:42
Definition XrdOucStream.hh:47
Definition XrdSysError.hh:90
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)