Handle case of missing metadata.json.
This commit is contained in:
parent
75956dd1ff
commit
55e6d65b1c
19
src/lib.rs
19
src/lib.rs
@ -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 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()))?;
|
||||
let old_metadata: HashMap<String, Value> = match File::open(&path) {
|
||||
Ok(f) => {
|
||||
let r = BufReader::new(f);
|
||||
serde_json::from_reader(r)?
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to open {}: {}", path.display(), e);
|
||||
HashMap::new()
|
||||
}
|
||||
};
|
||||
|
||||
info!("Read metadata, {} videos found", old_metadata.len());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user