Skip to content

Commit

Permalink
Emscripten support
Browse files Browse the repository at this point in the history
  • Loading branch information
xzfc committed Sep 22, 2022
1 parent f4f439c commit 7b795ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/entry.rs
Expand Up @@ -569,7 +569,7 @@ impl<'a> EntryFields<'a> {
}
return Ok(Unpacked::__Nonexhaustive);

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[allow(unused_variables)]
fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::Other, "Not implemented"))
Expand Down Expand Up @@ -746,7 +746,7 @@ impl<'a> EntryFields<'a> {
}

// Windows does not support posix numeric ownership IDs
#[cfg(any(windows, target_arch = "wasm32"))]
#[cfg(not(unix))]
fn _set_ownerships(
_: &Path,
_: &Option<&mut std::fs::File>,
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<'a> EntryFields<'a> {
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(all(unix, feature = "xattr"))))]
#[allow(unused_variables)]
fn _set_perms(
dst: &Path,
Expand Down Expand Up @@ -869,7 +869,11 @@ impl<'a> EntryFields<'a> {
}
// Windows does not completely support posix xattrs
// https://en.wikipedia.org/wiki/Extended_file_attributes#Windows_NT
#[cfg(any(windows, not(feature = "xattr"), target_arch = "wasm32"))]
#[cfg(any(
windows,
not(feature = "xattr"),
all(target_arch = "wasm32", not(target_os = "emscripten"))
))]
fn set_xattrs(_: &mut EntryFields, _: &Path) -> io::Result<()> {
Ok(())
}
Expand Down
18 changes: 9 additions & 9 deletions src/header.rs
Expand Up @@ -732,7 +732,7 @@ impl Header {
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[allow(unused_variables)]
fn fill_platform_from(&mut self, meta: &fs::Metadata, mode: HeaderMode) {
unimplemented!();
Expand Down Expand Up @@ -1546,7 +1546,7 @@ fn copy_path_into(mut slot: &mut [u8], path: &Path, is_link_name: bool) -> io::R
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
fn ends_with_slash(p: &Path) -> bool {
p.to_string_lossy().ends_with('/')
}
Expand All @@ -1562,7 +1562,7 @@ fn ends_with_slash(p: &Path) -> bool {
p.as_os_str().as_bytes().ends_with(&[b'/'])
}

#[cfg(any(windows, target_arch = "wasm32"))]
#[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten"))))]
pub fn path2bytes(p: &Path) -> io::Result<Cow<[u8]>> {
p.as_os_str()
.to_str()
Expand Down Expand Up @@ -1624,19 +1624,19 @@ pub fn bytes2path(bytes: Cow<[u8]>) -> io::Result<Cow<Path>> {
})
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub fn bytes2path(bytes: Cow<[u8]>) -> io::Result<Cow<Path>> {
Ok(match bytes {
Cow::Borrowed(bytes) => {
Cow::Borrowed({ Path::new(str::from_utf8(bytes).map_err(invalid_utf8)?) })
}
Cow::Owned(bytes) => {
Cow::Owned({ PathBuf::from(String::from_utf8(bytes).map_err(invalid_utf8)?) })
Cow::Borrowed(Path::new(str::from_utf8(bytes).map_err(invalid_utf8)?))
}
Cow::Owned(bytes) => Cow::Owned(PathBuf::from(
String::from_utf8(bytes).map_err(invalid_utf8)?,
)),
})
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
fn invalid_utf8<T>(_: T) -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, "Invalid utf-8")
}

0 comments on commit 7b795ae

Please sign in to comment.