Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "fsblobstore" -version = "0.0.3" +version = "0.0.4" edition = "2021" license = "0BSD" categories = [ "filesystem" ] keywords = [ "blob", "datastore" ] repository = "https://repos.qrnch.tech/pub/fsblobstore" @@ -18,10 +18,11 @@ ] [features] enumerate = ["dep:recstrm", "dep:walkdir"] get-fname = [] +mkbasedir = [] [dependencies] hex = { version = "0.4.3" } idbag = { version = "0.1.2" } recstrm = { version = "0.0.1", optional = true } Index: examples/rmall.rs ================================================================== --- examples/rmall.rs +++ examples/rmall.rs @@ -1,22 +1,23 @@ #[cfg(feature = "enumerate")] mod inner { - use std::{env, fs}; + use std::env; use fsblobstore::FsBlobStore; pub(super) fn main() { // // Set up datastore base directory // let curdir = env::current_dir().unwrap(); let datastoredir = curdir.join("datastore"); + #[cfg(not(feature = "mkbasedir"))] if !datastoredir.exists() { - fs::create_dir(&datastoredir).unwrap(); + std::fs::create_dir_all(&datastoredir).unwrap(); } - let bs = FsBlobStore::new(&datastoredir).unwrap(); + let bs = FsBlobStore::new(datastoredir).unwrap(); // // Enumerate all keys in content store // let (rx, jh) = bs.enumerate(); Index: examples/simple.rs ================================================================== --- examples/simple.rs +++ examples/simple.rs @@ -1,6 +1,6 @@ -use std::{env, fs, io::Write}; +use std::{env, io::Write}; use fsblobstore::FsBlobStore; use rand::Rng; @@ -8,15 +8,16 @@ // // Set up datastore base directory // let curdir = env::current_dir().unwrap(); let datastoredir = curdir.join("datastore"); + #[cfg(not(feature = "mkbasedir"))] if !datastoredir.exists() { - fs::create_dir(&datastoredir).unwrap(); + std::fs::create_dir_all(&datastoredir).unwrap(); } - let bs = FsBlobStore::new(&datastoredir).unwrap(); + let bs = FsBlobStore::new(datastoredir).unwrap(); // // Create a random buffer to be used as file contents // let mut buf = vec![0u8; 65536]; Index: src/lib.rs ================================================================== --- src/lib.rs +++ src/lib.rs @@ -4,10 +4,11 @@ //! # Features //! | Feature | Function //! |-------------|---------- //! | `enumerate` | Enable method for enumerating all keys in storage. //! | `get-fname` | Enable method for acquiring the path of a blob. +//! | `mkbasedir` | Auto-create the base directory in factory methods. //! //! The use of the `enumerate` and `get-fname` features are discouraged since //! they may encourage breaking the intended usage pattern for `FsBlobStore` //! instances. @@ -119,12 +120,20 @@ /// Create a new file system-backed blob storage engine. /// /// The `basedir` is where the blobs and temporary files will be stored. The /// caller must ensure that either `basedir` is absolute, or that the path /// remains valid throughout the object's lifetime. + /// + /// If the basedir does not exist, the pub fn new(basedir: impl AsRef) -> Result { let basedir = basedir.as_ref(); + + #[cfg(feature = "mkbasedir")] + if !basedir.exists() { + fs::create_dir_all(basedir)?; + } + Ok(Self { basedir: basedir.to_path_buf(), minsize: None, idbag: IdBag::new() }) @@ -133,10 +142,16 @@ pub fn with_minsize( basedir: impl AsRef, minsize: usize ) -> Result { let basedir = basedir.as_ref(); + + #[cfg(feature = "mkbasedir")] + if !basedir.exists() { + fs::create_dir_all(basedir)?; + } + Ok(Self { basedir: basedir.to_path_buf(), minsize: Some(minsize), idbag: IdBag::new() }) Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -1,10 +1,33 @@ # Change Log ## [Unreleased] -[Details](/vdiff?from=fsblobstore-0.0.2&to=trunk) +[Details](/vdiff?from=fsblobstore-0.0.4&to=trunk) + +### Added + +### Changed + +### Removed + +--- + +## [0.0.4] - 2024-01-30 + +[Details](/vdiff?from=fsblobstore-0.0.3&to=fsblobstore-0.0.4) + +### Changed + +- Update factory methods to create base directory if it doesn't exists, if the + `mkbasedir` feature is enabled. + +--- + +## [0.0.3] - 2024-01-30 + +[Details](/vdiff?from=fsblobstore-0.0.2&to=fsblobstore-0.0.3) ### Added - Add factory method `FsBlobStore::with_minsize()` to be able to use the memory buffer for "small files" support introduced in `tmpfile` 0.0.2. @@ -12,12 +35,10 @@ ### Changed - Update to `tmpfile` 0.0.2. -### Removed - --- ## [0.0.2] - 2024-01-29 [Details](/vdiff?from=fsblobstore-0.0.1&to=fsblobstore-0.0.2)