flowey_core/
util.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Utilities used by flowey_core and made avaiable for higher-level crates.
5
6use std::path::Path;
7
8/// Copies the contents of `src` into the directory `dst`.
9pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
10    fs_err::create_dir_all(&dst)?;
11    for entry in fs_err::read_dir(src.as_ref())? {
12        let entry = entry?;
13        let dst = dst.as_ref().join(entry.file_name());
14        if entry.file_type()?.is_dir() {
15            copy_dir_all(entry.path(), dst)?;
16        } else {
17            fs_err::copy(entry.path(), dst)?;
18        }
19    }
20    Ok(())
21}