summaryrefslogtreecommitdiff
path: root/src/data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/data.rs')
-rw-r--r--src/data.rs95
1 files changed, 0 insertions, 95 deletions
diff --git a/src/data.rs b/src/data.rs
deleted file mode 100644
index 2069110..0000000
--- a/src/data.rs
+++ /dev/null
@@ -1,95 +0,0 @@
-use crate::specification::{Create, FileCount};
-use log::debug;
-use std::fs::File;
-use std::path::{Path, PathBuf};
-use tempfile::{tempdir_in, TempDir};
-use walkdir::WalkDir;
-
-/// Test data management for Obnam benchmarks.
-///
-/// Each backup in a benchmark backs up some test data created for
-/// that backup. That data is later cleaned up. Is all handled by this
-/// structure.
-#[derive(Debug)]
-pub struct Data {
- live: TempDir,
-}
-
-/// Possible errors from managing data.
-#[derive(Debug, thiserror::Error)]
-pub enum DataError {
- /// Directory creation failed.
- #[error("Failed to create directory {0}: {1}")]
- CreateDirectory(PathBuf, std::io::Error),
-
- /// File creation failed.
- #[error("Failed to create file {0}: {1}")]
- CreateFile(PathBuf, std::io::Error),
-
- /// File counting failed.
- #[error("Failed to count files in {0}: {1}")]
- CountFiles(PathBuf, walkdir::Error),
-
- /// Failed to create a temporary directory.
- #[error(transparent)]
- CreateTemp(#[from] std::io::Error),
-}
-
-impl Data {
- pub(crate) fn new(tempdir: &Path) -> Result<Self, DataError> {
- let live = tempdir_in(&tempdir)?;
- debug!("created temporary directory {}", live.path().display());
- Ok(Self { live })
- }
-
- pub(crate) fn create(&self, create: &Create) -> Result<(), DataError> {
- debug!(
- "creating {} files in {}",
- create.files,
- self.live.path().display()
- );
- for i in 0..create.files {
- let filename = self.live.path().join(format!("{}", i));
- debug!("creating {}", filename.display());
- File::create(&filename).map_err(|err| DataError::CreateFile(filename, err))?;
- }
- Ok(())
- }
-
- pub(crate) fn rename(&self, count: &FileCount) -> Result<(), DataError> {
- debug!("renaming {} files", count.files);
- Ok(())
- }
-
- pub(crate) fn delete(&self, count: &FileCount) -> Result<(), DataError> {
- debug!("deleting {}", count.files);
- Ok(())
- }
-
- pub(crate) fn file_count(&self) -> Result<u64, DataError> {
- debug!("counting files in {}", self.live.path().display());
- let mut n = 0;
- for entry in WalkDir::new(&self.live).into_iter() {
- if let Err(err) = entry {
- return Err(DataError::CountFiles(self.live.path().to_path_buf(), err));
- }
- n += 1;
- }
- debug!("found {} files in {}", n, self.live.path().display());
- Ok(n)
- }
-
- pub(crate) fn file_size(&self) -> Result<u64, DataError> {
- debug!(
- "counting combined slze of files in {}",
- self.live.path().display()
- );
- let n = 0;
- debug!(
- "found {} bytes of data in {}",
- n,
- self.live.path().display()
- );
- Ok(n)
- }
-}