Fix a bug in refactoring the storage layer.

Attempting to load from disk when the file does not exist should not
return an error and should continue with an empty set of tokens.
This commit is contained in:
Glenn Griffin
2019-11-20 11:19:48 -08:00
parent 8f84553769
commit d4b80a0c5c

View File

@@ -227,7 +227,12 @@ pub(crate) struct DiskStorage {
impl DiskStorage {
pub(crate) async fn new(path: PathBuf) -> Result<Self, io::Error> {
let tokens = JSONTokens::load_from_file(&path).await?;
let tokens = match JSONTokens::load_from_file(&path).await {
Ok(tokens) => tokens,
Err(e) if e.kind() == io::ErrorKind::NotFound => JSONTokens::new(),
Err(e) => return Err(e),
};
// Writing to disk will happen in a separate task. This means in the
// common case returning a token to the user will not be required to
// wait for disk i/o. We communicate with a dedicated writer task via a