Skip to content

Commit

Permalink
core: Use "/" as path separator inside XDVDFSFilesystem (#74)
Browse files Browse the repository at this point in the history
* Use "/" as path separator for XDVDFS images in Windows, use full path when creating default output path

* Revert path parsing changes at cmd module

* Use "/" as a path separator in XDVDFSFilesystem related operations

* Format code at FS module
  • Loading branch information
astarivi authored Mar 8, 2024
1 parent a31db66 commit be4ef7f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions xdvdfs-core/src/write/fs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt::{Debug, Display};
use std::format;
use std::path::{Path, PathBuf};

use alloc::vec::Vec;
Expand Down Expand Up @@ -213,7 +214,12 @@ where
.into_iter()
.map(|dirent| {
Ok(FileEntry {
path: dir.join(&*dirent.name_str()?),
// Workaround to use "/" as a path separator in all platforms
path: PathBuf::from(format!(
"{}/{}",
if path == "/" { "" } else { path },
&*dirent.name_str()?
)),
file_type: if dirent.node.dirent.is_directory() {
FileType::Directory
} else {
Expand All @@ -234,7 +240,14 @@ where
offset: u64,
size: u64,
) -> Result<u64, E> {
let path = src.to_str().ok_or(util::Error::InvalidFileName)?;
// Replace the "\" path separators with "/"
let path = &src
.to_str()
.ok_or(util::Error::InvalidFileName)?
.split('\\')
.collect::<Vec<_>>()
.join("/");

let dirent = self
.volume
.root_table
Expand Down Expand Up @@ -264,7 +277,13 @@ where
}

async fn copy_file_buf(&mut self, src: &Path, buf: &mut [u8], offset: u64) -> Result<u64, E> {
let path = src.to_str().ok_or(util::Error::InvalidFileName)?;
let path = &src
.to_str()
.ok_or(util::Error::InvalidFileName)?
.split('\\')
.collect::<Vec<_>>()
.join("/");

let dirent = self
.volume
.root_table
Expand Down

0 comments on commit be4ef7f

Please sign in to comment.