casey / intermodal

A command-line utility for BitTorrent torrent file creation, verification, and more
https://imdl.io
Creative Commons Zero v1.0 Universal
487 stars 25 forks source link

Filter files hidden by attribute on MacOS #405

Open casey opened 4 years ago

casey commented 4 years ago

I opened a PR on ripgrep https://github.com/BurntSushi/ripgrep/pull/1557 to add a filter_entry method to ignore::WalkBuilder. Once that lands we can go back to filtering files hidden by attribute on MacOS. An improved implementation of that, without needing unsafe or libc::stat is:

  fn hidden(path: &Path) -> Result<bool, Error> {
    use std::os::macos::fs::MetadataExt;

    let metadata = path.metadata().context(error::Filesystem { path })?;

    const HIDDEN_MASK_MAC: u32 = 0x0000_8000;

    Ok(metadata.st_flags() & HIDDEN_MASK_MAC != 0)
  }