Skip to content

Commit

Permalink
Repair buffrs packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mara-schulke committed Dec 12, 2023
1 parent 5dad8eb commit 4a6d0e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ assets = [
["target/release/buffrs", "usr/bin/", "755"],
["LICENSE", "usr/share/doc/buffrs/", "644"],
["README.md", "usr/share/doc/buffrs/README", "644"],
]
]
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ pub async fn list() -> miette::Result<()> {
store.populate(pkg).await?;
}

let protos = store.collect(&store.proto_vendor_path()).await;
let protos = store.collect(&store.proto_vendor_path(), true).await;

let cwd = {
let cwd = std::env::current_dir()
Expand Down
4 changes: 2 additions & 2 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Generator {

proto_files.extend(store.populated_files(pkg).await);
} else {
proto_files.extend(store.collect(&store.proto_vendor_path()).await);
proto_files.extend(store.collect(&store.proto_vendor_path(), true).await);
}

let includes = &[store.proto_vendor_path()];
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Generator {

protos.extend(store.populated_files(pkg).await);
} else {
protos.extend(store.collect(&store.proto_vendor_path()).await);
protos.extend(store.collect(&store.proto_vendor_path(), true).await);
}

info!(":: initializing code generator");
Expand Down
20 changes: 12 additions & 8 deletions src/package/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl PackageStore {
let pkg_path = self.proto_path();
let mut entries = BTreeMap::new();

for entry in self.collect(&pkg_path).await {
for entry in self.collect(&pkg_path, false).await {
let path = entry.strip_prefix(&pkg_path).into_diagnostic()?;
let contents = tokio::fs::read(&entry).await.unwrap();
entries.insert(path.into(), contents.into());
Expand All @@ -204,11 +204,18 @@ impl PackageStore {
}

/// Collect .proto files in a given path
pub async fn collect(&self, path: &Path) -> Vec<PathBuf> {
pub async fn collect(&self, path: &Path, vendored: bool) -> Vec<PathBuf> {
let mut paths: Vec<_> = WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.map(|entry| entry.into_path())
.filter(|path| {
if vendored {
true
} else {
!path.starts_with(self.proto_vendor_path())
}
})
.filter(|path| {
let ext = path.extension().map(|s| s.to_str());

Expand Down Expand Up @@ -244,13 +251,10 @@ impl PackageStore {
))?;
}

for entry in self.collect(&source_path).await {
if entry.starts_with(self.proto_vendor_path()) {
continue;
}

for entry in self.collect(&source_path, false).await {
let file_name = entry.strip_prefix(&source_path).into_diagnostic()?;
let target_path = target_dir.join(file_name);

tokio::fs::create_dir_all(target_path.parent().unwrap())
.await
.into_diagnostic()
Expand All @@ -269,7 +273,7 @@ impl PackageStore {

/// Get the paths of all files under management after population
pub async fn populated_files(&self, manifest: &PackageManifest) -> Vec<PathBuf> {
self.collect(&self.populated_path(manifest)).await
self.collect(&self.populated_path(manifest), true).await
}
}

Expand Down

0 comments on commit 4a6d0e9

Please sign in to comment.