From 2c535388a938eb53e402eabc1bc0f325fd9b6449 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Mon, 4 Jun 2018 03:14:04 -0500 Subject: [PATCH] Allow for building on Windows. --- src/upload.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/upload.rs b/src/upload.rs index 0075279..79b0a41 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -17,7 +17,7 @@ * along with Actix Form Data. If not, see . */ -use std::{collections::HashMap, fs::DirBuilder, os::unix::fs::DirBuilderExt, path::Path, +use std::{collections::HashMap, fs::DirBuilder, path::{Path, PathBuf}, sync::{Arc, atomic::{AtomicUsize, Ordering}}}; use actix_web::{multipart, error::PayloadError}; @@ -127,6 +127,25 @@ where })) } +#[cfg(unix)] +fn build_dir(stored_dir: PathBuf) -> Result<(), Error> { + use std::os::unix::fs::DirBuilderExt; + + DirBuilder::new() + .recursive(true) + .mode(0o755) + .create(stored_dir) + .map_err(|_| Error::MkDir) +} + +#[cfg(not(unix))] +fn build_dir(stored_dir: PathBuf) -> Result<(), Error> { + DirBuilder::new() + .recursive(true) + .create(stored_dir) + .map_err(|_| Error::MkDir) +} + fn handle_file_upload( field: multipart::Field, gen: Arc, @@ -161,11 +180,7 @@ where let (tx, rx) = oneshot::channel(); match form.pool.execute(Box::new(lazy(move || { - let res = DirBuilder::new() - .recursive(true) - .mode(0o755) - .create(stored_dir.clone()) - .map_err(|_| Error::MkDir); + let res = build_dir(stored_dir.clone()); tx.send(res).map_err(|_| ()) }))) {