| 151 | |
| 152 | |
| 153 | hz::ExpectedVoid<StorageDeviceError> StorageDevice::parse_basic_data() |
| 154 | { |
| 155 | // Clear everything fetched before, except outputs and type |
| 156 | this->clear_parse_results(); |
| 157 | |
| 158 | // Detect the output format. |
| 159 | auto detect_status = SmartctlParser::detect_output_format(this->get_basic_output()); |
| 160 | auto output_format = SmartctlOutputFormat::Text; |
| 161 | if (detect_status.has_value()) { |
| 162 | output_format = detect_status.value(); |
| 163 | } else { |
| 164 | debug_out_warn("app", "Cannot detect smartctl output format. Assuming Text.\n"); |
| 165 | } |
| 166 | |
| 167 | // Parse using Basic parser. This supports all drive types. |
| 168 | auto basic_parser = SmartctlParser::create(SmartctlParserType::Basic, output_format); |
| 169 | DBG_ASSERT_RETURN(basic_parser, hz::Unexpected(StorageDeviceError::ParseError, _("Cannot create parser"))); |
| 170 | |
| 171 | // This also fills the drive type properties. |
| 172 | auto parse_status = basic_parser->parse(this->get_basic_output()); |
| 173 | if (!parse_status) { |
| 174 | std::string message = parse_status.error().message(); |
| 175 | return hz::Unexpected(StorageDeviceError::ParseError, |
| 176 | fmt::format(fmt::runtime(_("Cannot parse smartctl output: {}")), message)); |
| 177 | } |
| 178 | |
| 179 | // See if we can narrow down the drive type from what was detected |
| 180 | // by StorageDetector and properties set by Basic parser. |
| 181 | auto basic_property_repo = basic_parser->get_property_repository(); |
| 182 | |
| 183 | // Make detected type more exact. |
| 184 | detect_drive_type_from_properties(basic_property_repo); |
| 185 | |
| 186 | // Add property descriptions and set to the drive. |
| 187 | this->set_property_repository(StoragePropertyProcessor::process_properties(basic_property_repo, get_detected_type())); |
| 188 | |
| 189 | debug_out_dump("app", "Drive " << get_device_with_type() << " set to be " |
| 190 | << StorageDeviceDetectedTypeExt::get_displayable_name(get_detected_type()) << " device.\n"); |
| 191 | |
| 192 | read_common_properties(); // sets model_name_, etc. |
| 193 | |
| 194 | // A model field (and its aliases) is a good indication whether there was any data or not |
| 195 | set_parse_status(model_name_.has_value() ? ParseStatus::Basic : ParseStatus::None); |
| 196 | |
| 197 | // Try to parse the properties. ignore its errors - we already got what we came for. |
| 198 | // Note that this may try to parse data the second time (it may already have |
| 199 | // been parsed by parse_data() which failed at it). |
| 200 | // if (do_set_properties) { |
| 201 | // auto parser = SmartctlParser::create(SmartctlParserType::Ata, output_format); |
| 202 | // DBG_ASSERT_RETURN(parser, hz::Unexpected(StorageDeviceError::ParseError, _("Cannot create parser"))); |
| 203 | // |
| 204 | // if (parser->parse(this->basic_output_)) { // try to parse it |
| 205 | // this->set_property_repository( |
| 206 | // StoragePropertyProcessor::process_properties(parser->get_property_repository(), disk_type)); // copy to our drive, overwriting old data |
| 207 | // } |
| 208 | // } |
| 209 | |
| 210 | signal_changed().emit(this); // notify listeners |
no test coverage detected