non-utf8 paths now working

This commit is contained in:
ascendforever 2024-10-13 18:17:10 -04:00
parent 28a36d80cd
commit 39b56c390f

View file

@ -5,6 +5,7 @@ use crate::structopt::StructOpt;
use std::collections::HashSet; use std::collections::HashSet;
use std::io::Write; use std::io::Write;
use std::path::{Path,PathBuf}; use std::path::{Path,PathBuf};
use std::os::unix::ffi::OsStrExt;
@ -80,13 +81,18 @@ impl<'a> Registry<'a> {
} }
pub fn write_all(&self, writer: &mut impl Write, separator_null: bool, quote: bool) -> std::io::Result<()> { pub fn write_all(&self, writer: &mut impl Write, separator_null: bool, quote: bool) -> std::io::Result<()> {
if separator_null { let sep = if separator_null {
if quote { for (_,file) in &self.registry { write!(writer, "{}\0", shlex::try_quote(&file.to_string_lossy()).unwrap())?; } } '\0'
else { for (_,file) in &self.registry { write!(writer, "{}\0", &file.to_string_lossy() )?; } }
} else { } else {
if quote { for (_,file) in &self.registry { writeln!(writer, "{}", shlex::try_quote(&file.to_string_lossy()).unwrap())?; } } '\n'
else { for (_,file) in &self.registry { writeln!(writer, "{}", &file.to_string_lossy() )?; } } };
} if quote { for (_,file) in &self.registry {
writer.write_all(&shlex::bytes::try_quote(&file.as_os_str().as_bytes()).unwrap())?;
} }
else { for (_,file) in &self.registry {
writer.write_all(file.as_os_str().as_bytes())?;
} }
write!(writer, "{}", sep)?;
Ok(()) Ok(())
} }
@ -119,7 +125,7 @@ impl<'a> Registry<'a> {
None => eprintln!( None => eprintln!(
"Cannot read non-utf-8 file extension: {} on {}", "Cannot read non-utf-8 file extension: {} on {}",
shlex::try_quote(&osstr_ext.to_string_lossy()).unwrap(), shlex::try_quote(&osstr_ext.to_string_lossy()).unwrap(),
shlex::try_quote(&path.to_string_lossy()).unwrap() shlex::try_quote(&path.to_string_lossy()).unwrap(),
) )
} }
} }