Skip to content

Commit

Permalink
Ignore hidden files in GMA creation
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamVenner committed Sep 10, 2023
1 parent b06df9d commit 55367a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 6 additions & 1 deletion fastgmad-lib/src/create/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::{fastgmad_error, fastgmad_io_error, FastGmadError},
util::WriteEx,
util::{WriteEx, self},
whitelist,
};
use std::{
Expand Down Expand Up @@ -182,11 +182,16 @@ fn discover_entries(folder: &Path, ignore: &[String], warn_invalid: bool) -> Res
fastgmad_io_error!(while "walking directory", error: std::io::Error::new(std::io::ErrorKind::Other, "unknown"), path: path)
}
})?;

if !entry.file_type().is_file() {
continue;
}

let path = entry.path();
if matches!(util::is_hidden_file(path), Ok(true) | Err(_)) {
continue;
}

let relative_path = path
.strip_prefix(folder)
.map_err(|_| fastgmad_io_error!(error: std::io::Error::new(std::io::ErrorKind::InvalidData, "File not in addon directory"), path: path))?
Expand Down
23 changes: 22 additions & 1 deletion fastgmad-lib/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
use std::io::{BufRead, Write};
use std::{io::{BufRead, Write}, path::Path};

pub fn is_hidden_file(path: &Path) -> Result<bool, std::io::Error> {
let hidden;

#[cfg(unix)] {
if let Some(file_name) = path.file_name() {
use std::os::unix::prelude::OsStrExt;
hidden = file_name.as_bytes().starts_with(b".");
} else {
hidden = false;
}
}

#[cfg(windows)] {
use std::os::windows::fs::MetadataExt;
const HIDDEN: u32 = 0x00000002;
hidden = std::fs::metadata(path)?.file_attributes() & HIDDEN != 0;
}

Ok(hidden)
}

pub trait WriteEx: Write {
fn write_nul_str(&mut self, bytes: &[u8]) -> Result<(), std::io::Error>;
Expand Down

0 comments on commit 55367a2

Please sign in to comment.