MCPcopy Create free account
hub / github.com/cvmfs/cvmfs / ReadFromFile

Method ReadFromFile

cvmfs/uid_map.h:127–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126 protected:
127 bool ReadFromFile(const std::string &path) {
128 FILE *fmap = fopen(path.c_str(), "r");
129 if (!fmap) {
130 LogCvmfs(kLogUtility, kLogDebug, "failed to open %s (errno: %d)",
131 path.c_str(), errno);
132 return false;
133 }
134
135 const sanitizer::IntegerSanitizer int_sanitizer;
136
137 std::string line;
138 unsigned int line_number = 0;
139 while (GetLineFile(fmap, &line)) {
140 ++line_number;
141 line = Trim(line);
142 if (line.empty() || line[0] == '#') {
143 continue;
144 }
145
146 std::vector<std::string> components = SplitString(line, ' ');
147 FilterEmptyStrings(&components);
148 if (components.size() != 2 || !int_sanitizer.IsValid(components[1])
149 || (components[0] != "*" && !int_sanitizer.IsValid(components[0]))) {
150 fclose(fmap);
151 LogCvmfs(kLogUtility, kLogDebug, "failed to read line %d in %s",
152 line_number, path.c_str());
153 return false;
154 }
155
156 value_type const to = String2Uint64(components[1]);
157 if (components[0] == "*") {
158 SetDefault(to);
159 continue;
160 }
161
162 key_type const from = String2Uint64(components[0]);
163 Set(from, to);
164 }
165
166 fclose(fmap);
167 return true;
168 }
169
170 void FilterEmptyStrings(std::vector<std::string> *vec) const {
171 std::vector<std::string>::iterator i = vec->begin();

Callers

nothing calls this directly

Calls 8

LogCvmfsFunction · 0.85
GetLineFileFunction · 0.85
TrimFunction · 0.85
SplitStringFunction · 0.85
String2Uint64Function · 0.85
c_strMethod · 0.80
sizeMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected