Skip to content

Commit

Permalink
fix: handle already existing temp folder
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias-Boulay <[email protected]>
  • Loading branch information
Mathias-Boulay authored and BioTheWolff committed Apr 23, 2024
1 parent 4a2a8bb commit 5b4c1be
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/fs-gen/src/image_builder.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::{
fs::{self},
fs,
path::{Path, PathBuf},
sync::Arc,
thread,
};

use anyhow::{Context, Result};
use anyhow::anyhow;
use anyhow::{Context, Ok, Result};
use fuse_backend_rs::{
api::{filesystem::Layer, server::Server},
overlayfs::{config::Config, OverlayFs},
passthrough::{self, PassthroughFs},
transport::{FuseChannel, FuseSession},
};

static FILE_EXISTS_ERROR: i32 = 17;

pub struct FuseServer {
server: Arc<Server<Arc<OverlayFs>>>,
ch: FuseChannel,
Expand Down Expand Up @@ -41,12 +44,19 @@ fn new_passthroughfs_layer(rootdir: &str) -> Result<BoxedLayer> {

/// Ensure a destination folder is created
fn ensure_folder_created(output_folder: &Path) -> Result<()> {
fs::create_dir(output_folder).with_context(|| {
format!(
"Failed to ensure folder creation: {}",
output_folder.to_string_lossy()
)
})
let result = fs::create_dir(output_folder);

// If the file already exists, we're fine
if result.is_err()
&& result
.unwrap_err()
.raw_os_error()
.is_some_and(|err_val| err_val != FILE_EXISTS_ERROR)
{
return Err(anyhow!("Failed to create folder"));
}

Ok(())
}

/// Merges all the layers into a single folder for further manipulation
Expand Down

0 comments on commit 5b4c1be

Please sign in to comment.