summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-02-26 07:18:46 +0200
committerLars Wirzenius <liw@liw.fi>2022-03-03 18:54:32 +0200
commit83b83530c05e23945cfe5a11a2125c4d93d40a93 (patch)
tree59f2c38cd3e0214c3aea9b8f0b569193925dec25
parentdd8ac8901cd15945bce8d1a072abbcbdfe6d5a83 (diff)
downloadobnam2-83b83530c05e23945cfe5a11a2125c4d93d40a93.tar.gz
refactor: use FileId instead of raw type
This is clearer and less error prone. Sponsored-by: author
-rw-r--r--src/backup_run.rs3
-rw-r--r--src/cmd/backup.rs3
-rw-r--r--src/cmd/restore.rs9
-rw-r--r--src/generation.rs6
-rw-r--r--src/lib.rs2
5 files changed, 13 insertions, 10 deletions
diff --git a/src/backup_run.rs b/src/backup_run.rs
index 0b816bf..464179b 100644
--- a/src/backup_run.rs
+++ b/src/backup_run.rs
@@ -7,6 +7,7 @@ use crate::chunker::{ChunkerError, FileChunks};
use crate::chunkid::ChunkId;
use crate::client::{BackupClient, ClientError};
use crate::config::ClientConfig;
+use crate::dbgen::FileId;
use crate::error::ObnamError;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::fsiter::{AnnotatedFsEntry, FsIterError, FsIterator};
@@ -84,7 +85,7 @@ struct OneRootBackupOutcome {
#[derive(Debug)]
pub struct RootsBackupOutcome {
/// The number of backed up files.
- pub files_count: i64,
+ pub files_count: FileId,
/// The errors encountered while backing up files.
pub warnings: Vec<BackupError>,
/// CACHEDIR.TAG files that aren't present in in a previous generation.
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs
index 92b0f40..e4569e8 100644
--- a/src/cmd/backup.rs
+++ b/src/cmd/backup.rs
@@ -3,6 +3,7 @@
use crate::backup_run::BackupRun;
use crate::client::BackupClient;
use crate::config::ClientConfig;
+use crate::dbgen::FileId;
use crate::error::ObnamError;
use crate::generation::GenId;
@@ -76,7 +77,7 @@ impl Backup {
fn report_stats(
runtime: &SystemTime,
- file_count: i64,
+ file_count: FileId,
gen_id: &GenId,
num_warnings: usize,
) -> Result<(), ObnamError> {
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index 7b3d95e..983efbb 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -3,6 +3,7 @@
use crate::backup_reason::Reason;
use crate::client::{BackupClient, ClientError};
use crate::config::ClientConfig;
+use crate::dbgen::FileId;
use crate::error::ObnamError;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::generation::{LocalGeneration, LocalGenerationError};
@@ -132,7 +133,7 @@ pub enum RestoreError {
async fn restore_generation(
client: &BackupClient,
gen: &LocalGeneration,
- fileid: i64,
+ fileid: FileId,
entry: &FilesystemEntry,
to: &Path,
progress: &ProgressBar,
@@ -185,7 +186,7 @@ async fn restore_regular(
client: &BackupClient,
gen: &LocalGeneration,
path: &Path,
- fileid: i64,
+ fileid: FileId,
entry: &FilesystemEntry,
) -> Result<(), RestoreError> {
debug!("restoring regular {}", path.display());
@@ -293,9 +294,9 @@ fn path_to_cstring(path: &Path) -> CString {
CString::new(path).unwrap()
}
-fn create_progress_bar(file_count: i64, verbose: bool) -> ProgressBar {
+fn create_progress_bar(file_count: FileId, verbose: bool) -> ProgressBar {
let progress = if verbose {
- ProgressBar::new(file_count as u64)
+ ProgressBar::new(file_count)
} else {
ProgressBar::hidden()
};
diff --git a/src/generation.rs b/src/generation.rs
index 454bb50..2a886ad 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -2,6 +2,7 @@
use crate::backup_reason::Reason;
use crate::chunkid::ChunkId;
+use crate::dbgen::FileId;
use crate::fsentry::FilesystemEntry;
use rusqlite::Connection;
use serde::Serialize;
@@ -15,9 +16,6 @@ const SCHEMA_MAJOR: u32 = 0;
/// Current generation database schema minor version.
const SCHEMA_MINOR: u32 = 0;
-/// An identifier for a file in a generation.
-type FileId = i64;
-
/// An identifier for a generation.
#[derive(Debug, Clone)]
pub struct GenId {
@@ -250,7 +248,7 @@ impl LocalGeneration {
}
/// How many files are there in the local generation?
- pub fn file_count(&self) -> Result<i64, LocalGenerationError> {
+ pub fn file_count(&self) -> Result<FileId, LocalGenerationError> {
sql::file_count(&self.conn)
}
diff --git a/src/lib.rs b/src/lib.rs
index 8961df4..6a30334 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,6 +17,8 @@ pub mod cipher;
pub mod client;
pub mod cmd;
pub mod config;
+pub mod db;
+pub mod dbgen;
pub mod engine;
pub mod error;
pub mod fsentry;