fix: binary install is now working

This commit is contained in:
Strix 2023-10-14 22:39:49 +02:00
parent d436a49c8f
commit d6cfab4eb7
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
6 changed files with 96 additions and 43 deletions

40
pkgr/src/util/fs.rs Normal file
View file

@ -0,0 +1,40 @@
use std::path::Path;
use std::fs::DirEntry;
use std::{fs, io};
use log::trace;
pub fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> std::io::Result<()> {
if dir.is_dir() {
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
visit_dirs(&path, cb)?;
} else {
cb(&entry);
}
}
}
Ok(())
}
pub fn copy_recursively(source: &Path, target: &Path) -> io::Result<()> {
if source.is_file() {
trace!("source: {:?}, target: {:?}", source, target);
fs::copy(source, target)?;
} else if source.is_dir() {
if !target.exists() {
fs::create_dir(target)?;
}
for entry in fs::read_dir(source)? {
let entry = entry?;
let file_name = entry.file_name();
let source_path = entry.path();
let target_path = target.join(&file_name);
copy_recursively(&source_path, &target_path)?;
}
}
Ok(())
}

View file

@ -1,19 +1,2 @@
use std::fs::DirEntry;
use std::path::Path;
pub mod prompts;
pub fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> std::io::Result<()> {
if dir.is_dir() {
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
visit_dirs(&path, cb)?;
} else {
cb(&entry);
}
}
}
Ok(())
}
pub mod fs;