From 3a8078c32eb447951371a1f18c20e6106f0c2590 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 5 Mar 2022 14:29:19 +0000 Subject: [PATCH] move copy_dir_recursive into main.rs --- build_src/assets.rs | 16 ---------------- build_src/main.rs | 16 +++++++++++++++- build_src/webring.rs | 16 ---------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/build_src/assets.rs b/build_src/assets.rs index da4cc3c..fb9e906 100644 --- a/build_src/assets.rs +++ b/build_src/assets.rs @@ -1,21 +1,5 @@ -use std::{fs, path::Path}; - use crate::*; -fn copy_dir_recursive(src: impl AsRef, dst: impl AsRef) -> std::io::Result<()> { - fs::create_dir_all(&dst)?; - for entry in fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - if ty.is_dir() { - copy_dir_recursive(entry.path(), dst.as_ref().join(entry.file_name()))?; - } else { - fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; - } - } - Ok(()) -} - pub fn copy_assets(ctx: &BuildContext) -> Result<()> { log_info("Copying assets…"); copy_dir_recursive(ctx.source_dir.join("assets"), ctx.output_dir.join("assets"))?; diff --git a/build_src/main.rs b/build_src/main.rs index 1b10439..c2a3b10 100644 --- a/build_src/main.rs +++ b/build_src/main.rs @@ -1,5 +1,5 @@ use siru::prelude::*; -use std::{convert::TryInto, path::PathBuf, sync::Arc, time::Duration}; +use std::{convert::TryInto, fs, path::Path, path::PathBuf, sync::Arc, time::Duration}; type Result = std::result::Result>; @@ -27,6 +27,20 @@ impl SiruFS for BuildContext { } } +pub fn copy_dir_recursive(src: impl AsRef, dst: impl AsRef) -> std::io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_recursive(entry.path(), dst.as_ref().join(entry.file_name()))?; + } else { + fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) +} + fn build() { let ctx = BuildContext { source_dir: "src".try_into().unwrap(), diff --git a/build_src/webring.rs b/build_src/webring.rs index 9daf6d0..8a2184b 100644 --- a/build_src/webring.rs +++ b/build_src/webring.rs @@ -1,21 +1,5 @@ -use std::{fs, path::Path}; - use crate::*; -fn copy_dir_recursive(src: impl AsRef, dst: impl AsRef) -> std::io::Result<()> { - fs::create_dir_all(&dst)?; - for entry in fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - if ty.is_dir() { - copy_dir_recursive(entry.path(), dst.as_ref().join(entry.file_name()))?; - } else { - fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; - } - } - Ok(()) -} - pub fn copy_webring(ctx: &BuildContext) -> Result<()> { log_info("Copying webring…"); copy_dir_recursive(