-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(extract): unicode files on Linux
Unicode files being extracted to directories still caused issues on Linux. For example, if a file `❤️.txt` was part of a RAR archive, extracting it to CWD or by providing a parent dir would fail. This commit adds extensive tests and fixes all those issues definitively. Relates-to #44
- Loading branch information
Showing
7 changed files
with
161 additions
and
37 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::path::{Path, PathBuf}; | ||
use widestring::{WideCString, WideCStr}; | ||
|
||
pub(crate) type RarString = WideCString; | ||
pub(crate) type RarStr = WideCStr; | ||
|
||
pub(crate) fn construct(path: &Path) -> RarString { | ||
WideCString::from_os_str(path).expect("Unexpected nul in path") | ||
} | ||
|
||
pub(crate) fn process_file( | ||
handle: *const unrar_sys::Handle, | ||
operation: i32, | ||
dest_path: Option<&RarStr>, | ||
dest_name: Option<&RarStr>, | ||
) -> i32 { | ||
unsafe { | ||
unrar_sys::RARProcessFileW( | ||
handle, | ||
operation, | ||
dest_path.map(|path| path.as_ptr().cast()).unwrap_or(std::ptr::null()), | ||
dest_name.map(|file| file.as_ptr().cast()).unwrap_or(std::ptr::null()), | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn preprocess_extract( | ||
base: Option<&Path>, | ||
_filename: &PathBuf, | ||
) -> (Option<RarString>, Option<RarString>) { | ||
(base.map(construct), None) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::ffi::{CString, CStr}; | ||
use std::path::{Path, PathBuf}; | ||
|
||
pub(crate) type RarString = CString; | ||
pub(crate) type RarStr = CStr; | ||
|
||
pub(crate) fn construct<P: AsRef<std::path::Path>>(path: P) -> RarString { | ||
CString::new(path.as_ref().as_os_str().as_encoded_bytes()).unwrap() | ||
} | ||
|
||
pub(crate) fn process_file( | ||
handle: *const unrar_sys::Handle, | ||
operation: i32, | ||
dest_path: Option<&RarStr>, | ||
dest_name: Option<&RarStr>, | ||
) -> i32 { | ||
unsafe { | ||
unrar_sys::RARProcessFile( | ||
handle, | ||
operation, | ||
dest_path.map(|path| path.as_ptr().cast()).unwrap_or(std::ptr::null()), | ||
dest_name.map(|file| file.as_ptr().cast()).unwrap_or(std::ptr::null()), | ||
) | ||
} | ||
} | ||
|
||
pub(crate) fn preprocess_extract( | ||
base: Option<&Path>, | ||
filename: &PathBuf, | ||
) -> (Option<RarString>, Option<RarString>) { | ||
(None, Some(construct(base.unwrap_or(".".as_ref()).join(filename)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[cfg_attr(target_os = "linux", path = "linux.rs")] | ||
#[cfg_attr(not(target_os = "linux"), path = "all.rs")] | ||
mod os; | ||
|
||
pub(crate) use os::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5e6b83d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you release a patch version ? since this commit is very important