Skip to content

Commit

Permalink
Fix ZipStorageAdapter on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Sep 12, 2024
1 parent 279c587 commit 4f0c45f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fix `ArrayShardedExt::inner_chunk_grid` when applied on a sharded array with the `transpose` codec preceding `sharding_indexed`
- Fix `ZipStorageAdapter` on windows

## [0.17.0-beta.0] - 2024-09-06

Expand Down
21 changes: 14 additions & 7 deletions zarrs_storage/src/storage_adapter/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,26 @@ impl<TStorage: ?Sized + ReadableStorageTraits> ZipStorageAdapter<TStorage> {
})
}

fn key_str_to_zip_path(&self, key: &str) -> String {
let mut zip_name = self.zip_path.clone();
zip_name.push(key);

let zip_name = zip_name.to_string_lossy();
#[cfg(windows)]
{
zip_name = zip_name.replace("\\", "/");
}
zip_name.to_string()
}

fn get_impl(
&self,
key: &StoreKey,
byte_ranges: &[ByteRange],
) -> Result<Option<Vec<Bytes>>, StorageError> {
let mut zip_archive = self.zip_archive.lock();
let mut zip_name = self.zip_path.clone();
zip_name.push(key.as_str());

let mut file = {
let zip_file = zip_archive.by_name(&zip_name.to_string_lossy());
let zip_file = zip_archive.by_name(&self.key_str_to_zip_path(key.as_str()));
match zip_file {
Ok(zip_file) => zip_file,
Err(err) => match err {
Expand Down Expand Up @@ -145,9 +154,7 @@ impl<TStorage: ?Sized + ReadableStorageTraits> ListableStorageTraits
.into_iter()
.filter_map(|name| {
if name.starts_with(prefix.as_str()) {
let mut zip_name = self.zip_path.clone();
zip_name.push(&name);
if let Ok(file) = zip_archive.by_name(&zip_name.to_string_lossy()) {
if let Ok(file) = zip_archive.by_name(&self.key_str_to_zip_path(&name)) {
if file.is_file() {
let name = name.strip_suffix('/').unwrap_or(&name);
if let Ok(store_key) = StoreKey::try_from(name) {
Expand Down

0 comments on commit 4f0c45f

Please sign in to comment.