Skip to content

Commit

Permalink
ci: fix fmt (#29)
Browse files Browse the repository at this point in the history
* ci: fix fmt
  • Loading branch information
killagu authored Aug 10, 2023
1 parent bd6443c commit df2369f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ bindings/*/index.node
packages/cli/test/fixtures/project-scripts/apps/a/1
packages/downloader/test/nginx.conf
package-lock.json

# napi-rs generate wrong type ignore for tmp
packages/binding/index.d.ts
2 changes: 1 addition & 1 deletion packages/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use downloader::download::Downloader;
use downloader::error::Error as TnpmError;
use downloader::http::{HTTPPool, HTTPReqwester};
use downloader::store::listener::{EntryListener, PackageEntry};
use downloader::toc_index_store::{TocIndexStore};
use downloader::toc_index_store::TocIndexStore;
use downloader::{
download as batch_download, DownloadOptions, NpmStore, PackageRequest, PackageRequestBuilder,
TocIndex, TocPath,
Expand Down
9 changes: 6 additions & 3 deletions packages/downloader/src/store/stargz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//
// Stargz support.

use std::borrow::Cow;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;

use std::collections::HashMap;
use std::ops::Range;
Expand Down Expand Up @@ -136,7 +136,8 @@ impl TocIndex<'_> {
pub fn partition_clone(toc_index: &TocIndex, range: Range<usize>) -> TocIndex<'static> {
TocIndex {
version: toc_index.version,
entries: toc_index.entries[range.start..range.end].iter()
entries: toc_index.entries[range.start..range.end]
.iter()
.map(|f| f.to_owned())
.collect(),
}
Expand All @@ -145,7 +146,9 @@ impl TocIndex<'_> {
pub fn clone(toc_index: &TocIndex) -> TocIndex<'static> {
TocIndex {
version: toc_index.version,
entries: toc_index.entries.iter()
entries: toc_index
.entries
.iter()
.map(|f| TocEntry::to_owned(f))
.collect(),
}
Expand Down
27 changes: 15 additions & 12 deletions packages/downloader/src/store/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ impl TryInto<TocEntry<'_>> for &Header {
} // todo!("not supoort type: {:?}", self.entry_type()),
}),
size: self.size().unwrap(),
link_name: Cow::Owned(self
.link_name()
.unwrap()
.map_or_else(|| PathBuf::from(""), PathBuf::from)),
link_name: Cow::Owned(
self.link_name()
.unwrap()
.map_or_else(|| PathBuf::from(""), PathBuf::from),
),
mode: self.mode().unwrap(),
// FIXME: tokio-tar 读 uid 时会失败
// Custom { kind: Other, error: "numeric field was not a number: when getting uid for package/LICENSE" }
uid: 0, // header.uid().unwrap() as u32,
gid: 0, // header.gid().unwrap() as u32,
uname: Cow::Owned(self
.username()
.unwrap()
.map_or_else(|| String::from(""), String::from)),
gname: Cow::Owned(self
.groupname()
.unwrap()
.map_or_else(|| String::from(""), String::from)),
uname: Cow::Owned(
self.username()
.unwrap()
.map_or_else(|| String::from(""), String::from),
),
gname: Cow::Owned(
self.groupname()
.unwrap()
.map_or_else(|| String::from(""), String::from),
),
offset: 0,
dev_major: 0,
dev_minor: 0,
Expand Down
82 changes: 53 additions & 29 deletions packages/downloader/src/toc_index_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ impl<'a> TocIndexStoreInner<'a> {
}

impl TocIndexStoreInner<'_> {
fn restore(mut inner_toc_map_string: String, mut inner_toc_index_string: String) -> Result<TocIndexStoreInner<'static>> {
fn restore(
mut inner_toc_map_string: String,
mut inner_toc_index_string: String,
) -> Result<TocIndexStoreInner<'static>> {
let holder = TocIndexStoreInnerHolder {
inner_toc_map_string,
inner_toc_index_string,
Expand All @@ -66,8 +69,9 @@ impl TocIndexStoreInner<'_> {
unsafe {
let toc_map: TocMap = serde_json::from_str(&(*holder_ptr).inner_toc_map_string)
.map_err(|e| Error::FormatError(String::from("parse toc map file failed")))?;
let indices: TocIndicesMap = serde_json::from_str(&(*holder_ptr).inner_toc_index_string)
.map_err(|e| Error::FormatError(String::from("parse toc index file failed")))?;
let indices: TocIndicesMap =
serde_json::from_str(&(*holder_ptr).inner_toc_index_string)
.map_err(|e| Error::FormatError(String::from("parse toc index file failed")))?;
inner.toc_map = toc_map;
inner.indices = indices;
}
Expand Down Expand Up @@ -123,7 +127,13 @@ impl TocIndexStore {
})
}

pub fn add_package(&self, name: &str, version: &str, blob_id: &str, mut toc_index: TocIndex<'static>) {
pub fn add_package(
&self,
name: &str,
version: &str,
blob_id: &str,
mut toc_index: TocIndex<'static>,
) {
let pkg_entry_count = toc_index.entries.len();
let index_start = self.add_package_toc(blob_id, toc_index);
self.add_package_index(
Expand Down Expand Up @@ -173,30 +183,37 @@ impl TocIndexStore {

#[cfg(test)]
mod test {
use crate::store::TocEntry;
use crate::toc_index_store::TocIndexStore;
use crate::TocIndex;
use std::borrow::Cow;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use crate::store::TocEntry;
use crate::toc_index_store::TocIndexStore;
use crate::TocIndex;

#[test]
fn test_restore_from_package() {
let start = SystemTime::now();
let current_dir = std::env::current_dir().unwrap();

TocIndexStore::restore_from_file(
Path::new("/Users/killa/.rapid/cache/tar_buckets/npm.config.json"),
Path::new("/Users/killa/.rapid/cache/tar_buckets/npm.index.json")).unwrap();
current_dir.join("test/fixtures/meta/large_file/npm.config.json"),
current_dir.join("test/fixtures/meta/large_file/npm.index.json"),
)
.unwrap();
println!("cost {:?}", start.elapsed());
}

#[test]
fn test_get_package() {
let store = TocIndexStore::new();
store.add_package("uuid", "8.3.2", "bucket_0.stgz", TocIndex {
version: 1,
entries: vec![
TocEntry {
store.add_package(
"uuid",
"8.3.2",
"bucket_0.stgz",
TocIndex {
version: 1,
entries: vec![TocEntry {
name: Cow::Owned(PathBuf::from("[email protected]/dist/bin/uuid")),
toc_type: Cow::Owned(String::from("reg")),
size: 44,
Expand All @@ -210,16 +227,21 @@ mod test {
dev_major: 0,
dev_minor: 0,
xattrs: HashMap::new(),
digest: Cow::Owned(String::from("sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7")),
chunk_offset:0,
chunk_size:0
}
],
});
store.add_package("uuid", "9.0.0", "bucket_0.stgz", TocIndex {
version: 1,
entries: vec![
TocEntry {
digest: Cow::Owned(String::from(
"sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7",
)),
chunk_offset: 0,
chunk_size: 0,
}],
},
);
store.add_package(
"uuid",
"9.0.0",
"bucket_0.stgz",
TocIndex {
version: 1,
entries: vec![TocEntry {
name: Cow::Owned(PathBuf::from("[email protected]/dist/bin/uuid")),
toc_type: Cow::Owned(String::from("reg")),
size: 44,
Expand All @@ -233,12 +255,14 @@ mod test {
dev_major: 0,
dev_minor: 0,
xattrs: HashMap::new(),
digest: Cow::Owned(String::from("sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7")),
chunk_offset:0,
chunk_size:0
}
],
});
digest: Cow::Owned(String::from(
"sha256:30b5422b6c95ccdc402effd7d3354ca6a6bce621cf21d0379749ddf1f96c1ad7",
)),
chunk_offset: 0,
chunk_size: 0,
}],
},
);
let res = store.get_package("uuid", "8.3.2");
assert!(res.is_some());
let res = res.unwrap();
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit df2369f

Please sign in to comment.