| 213 | }; |
| 214 | |
| 215 | bool vtkCompositeCellGridReader::UpdateMetadata() |
| 216 | { |
| 217 | if (this->MetadataTime.GetMTime() >= this->GetMTime()) |
| 218 | { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | MetadataGuard meta(this); |
| 223 | if (!this->FileName) |
| 224 | { // Make sure we have a file to read. |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | // All files listed in this->FileName must be absolute or are assumed |
| 229 | // relative to the location of this->FileName. Get the absolute path |
| 230 | // for this->FileName so we can turn relative paths into absolute ones. |
| 231 | std::string err; |
| 232 | auto realFileName = vtksys::SystemTools::GetRealPath(this->FileName, &err); |
| 233 | if (!err.empty()) |
| 234 | { |
| 235 | vtkErrorMacro("Could not determine location of \"" << this->FileName << "\"."); |
| 236 | return false; |
| 237 | } |
| 238 | std::vector<std::string> pathParts; |
| 239 | vtksys::SystemTools::SplitPath(realFileName, pathParts); |
| 240 | if (pathParts.size() < 2) |
| 241 | { |
| 242 | vtkErrorMacro("Could not determine parent directory of \"" << this->FileName << "\"."); |
| 243 | return false; |
| 244 | } |
| 245 | pathParts.pop_back(); // Drop the filename so we are left with the parent directory. |
| 246 | |
| 247 | // Check the file's validity. |
| 248 | std::ifstream file(this->FileName); |
| 249 | if (!file.good()) |
| 250 | { |
| 251 | vtkErrorMacro("Cannot read file \"" << this->FileName << "\"."); |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | // Read the file into nlohmann json. |
| 256 | nlohmann::json jj; |
| 257 | try |
| 258 | { |
| 259 | jj = nlohmann::json::parse(file); |
| 260 | } |
| 261 | catch (...) |
| 262 | { |
| 263 | vtkErrorMacro("Cannot parse file \"" << this->FileName << "\"."); |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | vtkLogScopeF(TRACE, "UpdateMetadata"); |
| 268 | bool isComposite = true; |
| 269 | auto jtype = jj.find("data-type"); |
| 270 | if (jtype == jj.end()) |
| 271 | { |
| 272 | vtkErrorMacro("Data type is missing."); |
no test coverage detected