Rename and document file functions for readability.

This commit is contained in:
Tim Bruijnzeels
2022-02-18 18:02:55 +01:00
parent d19b4653e6
commit a078c407ca
3 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ impl KeyValueStore {
KeyValueStore::Disk(disk_store) => {
// If this is a new store then initialise the disk and set the version
if !disk_store.base.exists() {
file::create_dir(&disk_store.base)?;
file::create_dir_all(&disk_store.base)?;
store.version_set_current()?;
}
}
@@ -392,7 +392,7 @@ impl KeyValueStoreDiskImpl {
pub fn wipe(&self) -> Result<(), KeyValueError> {
if self.base.exists() {
file::remove_dir_all(&self.base)?;
file::create_dir(&self.base)?;
file::create_dir_all(&self.base)?;
}
Ok(())
}
+6 -2
View File
@@ -22,11 +22,12 @@ use crate::commons::{
pub fn sub_dir(base: &Path, name: &str) -> Result<PathBuf, KrillIoError> {
let mut full_path = base.to_path_buf();
full_path.push(name);
create_dir(&full_path)?;
create_dir_all(&full_path)?;
Ok(full_path)
}
pub fn create_dir(dir: &Path) -> Result<(), KrillIoError> {
/// Creates a dir and any parent dirs which were missing.
pub fn create_dir_all(dir: &Path) -> Result<(), KrillIoError> {
if !dir.is_dir() {
fs::create_dir_all(dir)
.map_err(|e| KrillIoError::new(format!("could not create dir: {}", dir.to_string_lossy()), e))?;
@@ -34,6 +35,7 @@ pub fn create_dir(dir: &Path) -> Result<(), KrillIoError> {
Ok(())
}
/// Removes a dir and all its content.
pub fn remove_dir_all(dir: &Path) -> Result<(), KrillIoError> {
if dir.exists() {
fs::remove_dir_all(dir)
@@ -42,6 +44,8 @@ pub fn remove_dir_all(dir: &Path) -> Result<(), KrillIoError> {
Ok(())
}
/// Creates a new File or opens an exiting one. If the file did not exist, the dir dir path
/// will be created if it did not exist yet.
pub fn create_file_with_path(path: &Path) -> Result<File, KrillIoError> {
if !path.exists() {
if let Some(parent) = path.parent() {
+1 -1
View File
@@ -321,7 +321,7 @@ pub async fn prepare_upgrade_data_migrations(
} else if versions.from < KrillVersion::release(0, 9, 0) {
let upgrade_data_dir = config.upgrade_data_dir();
if !upgrade_data_dir.exists() {
file::create_dir(&upgrade_data_dir)?;
file::create_dir_all(&upgrade_data_dir)?;
}
// Get a lock to ensure that only one process can run this migration