summaryrefslogtreecommitdiff
path: root/src/cmd/restore.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/restore.rs')
-rw-r--r--src/cmd/restore.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index 7956b5f..0051d20 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -7,14 +7,25 @@ use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
+use tempfile::NamedTempFile;
+
+pub fn restore(config: &Path, gen_id: &str, to: &Path) -> anyhow::Result<()> {
+ // Create a named temporary file. We don't meed the open file
+ // handle, so we discard that.
+ let dbname = {
+ let temp = NamedTempFile::new()?;
+ let (_, dbname) = temp.keep()?;
+ dbname
+ };
-pub fn restore(config: &Path, gen_id: &str, dbname: &Path, to: &Path) -> anyhow::Result<()> {
let config = ClientConfig::read_config(&config).unwrap();
let client = BackupClient::new(&config.server_url)?;
let gen_chunk = client.fetch_generation(&gen_id)?;
debug!("gen: {:?}", gen_chunk);
+
{
+ // Fetch the SQLite file, storing it in the temporary file.
let mut dbfile = File::create(&dbname)?;
for id in gen_chunk.chunk_ids() {
let chunk = client.fetch_chunk(id)?;
@@ -28,6 +39,9 @@ pub fn restore(config: &Path, gen_id: &str, dbname: &Path, to: &Path) -> anyhow:
restore_generation(&client, &gen, fileid, entry, &to)?;
}
+ // Delete the temporary file.
+ std::fs::remove_file(&dbname)?;
+
Ok(())
}