Handle case of missing metadata.json.

This commit is contained in:
Bill Thiede 2019-11-04 20:31:20 -08:00
parent 75956dd1ff
commit 55e6d65b1c

View File

@ -383,16 +383,17 @@ impl MovieLibrary {
pub fn update_metadata(&self) -> Result<Vec<String>, Error> {
let path = Path::new(&self.root).join(FULL_METADATA_FILENAME);
// TODO(wathiede): if we fail to parse the old file (i.e. file not found), create an empty
// old_metadata and keep going.
// Open the file in read-only mode with buffer.
let f = File::open(&path).context(format!("open {}", path.display()))?;
let old_metadata: HashMap<String, Value> = match File::open(&path) {
Ok(f) => {
let r = BufReader::new(f);
// Read the JSON contents of the file as an instance of `User`.
let old_metadata: HashMap<String, Value> = serde_json::from_reader(r)
.context(format!("serde_json::from_reader {}", path.display()))?;
serde_json::from_reader(r)?
}
Err(e) => {
error!("Failed to open {}: {}", path.display(), e);
HashMap::new()
}
};
info!("Read metadata, {} videos found", old_metadata.len());