1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.

use std::fs;
use std::path::Path;
use walkdir::WalkDir;

use crate::Error;

/// # Errors
/// Returns error if failed to walk through directory.
pub fn get_folder_size(dir: &Path) -> Result<u64, Error> {
    let mut total_size = 0;
    for entry in WalkDir::new(dir) {
        let entry = entry?;
        let path = entry.path();
        if path.is_file() {
            total_size += fs::metadata(path)?.len();
        }
    }

    Ok(total_size)
}

#[must_use]
pub const fn default_true() -> bool {
    true
}

#[must_use]
pub const fn default_false() -> bool {
    false
}

/// # Errors
/// Returns error if failed to remove some file.
pub fn rmdir<P: AsRef<Path>>(p: P) -> Result<(), Error> {
    fs::remove_dir_all(p)?;
    Ok(())
}

/// # Errors
/// todo
pub fn mv<P: AsRef<Path>>(_src_pathtern: &str, _dest: P) -> Result<(), Error> {
    Ok(())
}