| 19 | |
| 20 | impl SnapshotBackend { |
| 21 | pub(super) fn open(path: &Path, create: bool) -> Result<Self, DatabaseError> { |
| 22 | let file = OpenOptions::new() |
| 23 | .read(true) |
| 24 | .write(true) |
| 25 | .create(create) |
| 26 | .truncate(false) |
| 27 | .open(path)?; |
| 28 | // create_with_backend also initializes empty files. Existing-only |
| 29 | // opens must retain their refusal to initialize an empty database. |
| 30 | if !create && file.metadata()?.len() == 0 { |
| 31 | return Err(io::Error::new( |
| 32 | io::ErrorKind::InvalidData, |
| 33 | "existing pristine database is empty", |
| 34 | ) |
| 35 | .into()); |
| 36 | } |
| 37 | Ok(Self(Arc::new(FileBackend::new(file)?))) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl StorageBackend for SnapshotBackend { |