diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-10-28 16:19:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 16:19:55 -0400 |
commit | edaceecec771cf0395639175b5a21d20530f6080 (patch) | |
tree | 8c9708d095a8ed7c9e897869a68f9d2c9b4d7ffd /cli/fs_util.rs | |
parent | 2c674dcd20aeb19d694e03d969f5792d1581e87a (diff) |
feat: support npm specifiers in `deno info` for display text output only (#16470)
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r-- | cli/fs_util.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs index 365c9b430..fa1535469 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -1,7 +1,8 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::anyhow::Context; -use deno_core::error::{uri_error, AnyError}; +use deno_core::error::uri_error; +use deno_core::error::AnyError; pub use deno_core::normalize_path; use deno_core::ModuleSpecifier; use deno_runtime::deno_crypto::rand; @@ -9,8 +10,11 @@ use deno_runtime::deno_node::PathClean; use std::borrow::Cow; use std::env::current_dir; use std::fs::OpenOptions; -use std::io::{Error, ErrorKind, Write}; -use std::path::{Path, PathBuf}; +use std::io::Error; +use std::io::ErrorKind; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; use walkdir::WalkDir; pub fn atomic_write_file<T: AsRef<[u8]>>( @@ -573,6 +577,20 @@ pub fn root_url_to_safe_local_dirname(root: &ModuleSpecifier) -> PathBuf { result } +/// Gets the total size (in bytes) of a directory. +pub fn dir_size(path: &Path) -> std::io::Result<u64> { + let entries = std::fs::read_dir(path)?; + let mut total = 0; + for entry in entries { + let entry = entry?; + total += match entry.metadata()? { + data if data.is_dir() => dir_size(&entry.path())?, + data => data.len(), + }; + } + Ok(total) +} + #[cfg(test)] mod tests { use super::*; |