From 39b56c390f21ee609f0d2b16372d4d54540e1256 Mon Sep 17 00:00:00 2001 From: ascendforever Date: Sun, 13 Oct 2024 18:17:10 -0400 Subject: [PATCH] non-utf8 paths now working --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index a361d4d..6b8674e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use crate::structopt::StructOpt; use std::collections::HashSet; use std::io::Write; 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<()> { - if separator_null { - if quote { for (_,file) in &self.registry { write!(writer, "{}\0", shlex::try_quote(&file.to_string_lossy()).unwrap())?; } } - else { for (_,file) in &self.registry { write!(writer, "{}\0", &file.to_string_lossy() )?; } } + let sep = if separator_null { + '\0' } else { - if quote { for (_,file) in &self.registry { writeln!(writer, "{}", shlex::try_quote(&file.to_string_lossy()).unwrap())?; } } - else { for (_,file) in &self.registry { writeln!(writer, "{}", &file.to_string_lossy() )?; } } - } + '\n' + }; + 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(()) } @@ -119,7 +125,7 @@ impl<'a> Registry<'a> { None => eprintln!( "Cannot read non-utf-8 file extension: {} on {}", 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(), ) } }