Skip to content

Commit ad3473c

Browse files
committed
Add file is_hidden check
commit-id:e0d74a40
1 parent 3e485db commit ad3473c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scarb/src/process.rs

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{fmt, thread};
77

88
use anyhow::{anyhow, bail, Context, Result};
99
use tracing::{debug, debug_span, warn, Span};
10+
use walkdir::DirEntry;
1011

1112
use crate::core::Config;
1213
use crate::ui::{Spinner, Status};
@@ -163,3 +164,29 @@ pub fn make_executable(path: &Path) {
163164

164165
#[cfg(windows)]
165166
pub fn make_executable(_path: &Path) {}
167+
168+
#[cfg(unix)]
169+
pub fn is_hidden(entry: &DirEntry) -> bool {
170+
is_hidden_by_dot(entry)
171+
}
172+
173+
#[cfg(windows)]
174+
pub fn is_hidden(entry: &DirEntry) -> bool {
175+
use std::os::windows::prelude::*;
176+
177+
let is_hidden = std::fs::metadata(entry.path())
178+
.ok()
179+
.map(|metadata| metadata.file_attributes())
180+
.map(|attributes| (attributes & 0x2) > 0)
181+
.unwrap_or(false);
182+
183+
is_hidden || is_hidden_by_dot(entry)
184+
}
185+
186+
fn is_hidden_by_dot(entry: &DirEntry) -> bool {
187+
entry
188+
.file_name()
189+
.to_str()
190+
.map(|s| s.starts_with('.'))
191+
.unwrap_or(false)
192+
}

0 commit comments

Comments
 (0)