| 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(); |
nothing calls this directly
no test coverage detected