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> { pub fn update_metadata(&self) -> Result<Vec<String>, Error> {
let path = Path::new(&self.root).join(FULL_METADATA_FILENAME); 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 old_metadata: HashMap<String, Value> = match File::open(&path) {
let f = File::open(&path).context(format!("open {}", path.display()))?; Ok(f) => {
let r = BufReader::new(f); let r = BufReader::new(f);
serde_json::from_reader(r)?
// Read the JSON contents of the file as an instance of `User`. }
let old_metadata: HashMap<String, Value> = serde_json::from_reader(r) Err(e) => {
.context(format!("serde_json::from_reader {}", path.display()))?; error!("Failed to open {}: {}", path.display(), e);
HashMap::new()
}
};
info!("Read metadata, {} videos found", old_metadata.len()); info!("Read metadata, {} videos found", old_metadata.len());