Skip to content

Commit 04a8a2b

Browse files
committed
clean up pass complete
1 parent 87dcb28 commit 04a8a2b

42 files changed

Lines changed: 748 additions & 1257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/socket-patch-cli/src/commands/setup.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ use socket_patch_core::package_json::update::{
1313
remove_package_json, update_package_json, RemoveResult, RemoveStatus, UpdateResult,
1414
UpdateStatus,
1515
};
16-
use socket_patch_core::pth_hook::{
17-
add_hook_dependency, deps_contain_hook, detect_python_pm, pyproject_contains_hook,
18-
remove_hook_dependency, ManifestKind, PthEditResult, PthStatus, PythonPackageManager,
16+
use socket_patch_core::pth_hook::detect::{
17+
deps_contain_hook, detect_python_pm, PythonPackageManager,
18+
};
19+
use socket_patch_core::pth_hook::edit::{
20+
add_hook_dependency, pyproject_contains_hook, remove_hook_dependency, ManifestKind,
21+
PthEditResult, PthStatus,
1922
};
2023
use socket_patch_core::utils::telemetry::track_patch_setup;
2124
use socket_patch_core::vex::applied_patches;

crates/socket-patch-cli/src/commands/vex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use socket_patch_core::manifest::operations::read_manifest;
2222
use socket_patch_core::manifest::schema::PatchManifest;
2323
use socket_patch_core::utils::telemetry::{track_vex_failed, track_vex_generated};
2424
use socket_patch_core::vex::{
25-
build_document_with_provenance, detect_product, BuildOptions, Document, FailedPatch,
26-
VendorContext, VerifyOutcome,
25+
build_document, detect_product, BuildOptions, Document, FailedPatch, VendorContext,
26+
VerifyOutcome,
2727
};
2828

2929
use crate::args::{apply_env_toggles, parse_bool_flag, GlobalArgs};
@@ -413,7 +413,7 @@ async fn generate_vex(
413413
tooling: Some(format!("socket-patch {}", env!("CARGO_PKG_VERSION"))),
414414
};
415415

416-
let doc = match build_document_with_provenance(
416+
let doc = match build_document(
417417
manifest,
418418
&outcome.applied,
419419
&outcome.vendored,

crates/socket-patch-core/src/crawlers/composer_crawler.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
33

44
use super::types::{CrawledPackage, CrawlerOptions};
55
use crate::utils::fs::{is_dir, is_file};
6+
use crate::utils::process::{CommandRunner, SystemCommandRunner};
67

78
/// PHP/Composer ecosystem crawler for discovering packages in Composer
89
/// vendor directories.
@@ -226,16 +227,10 @@ async fn get_composer_home() -> Option<PathBuf> {
226227
}
227228

228229
// Try `composer global config home`
229-
if let Ok(output) = std::process::Command::new("composer")
230-
.args(["global", "config", "home"])
231-
.output()
232-
{
233-
if output.status.success() {
234-
if let Some(path) = parse_composer_home_output(&String::from_utf8_lossy(&output.stdout))
235-
{
236-
if is_dir(&path).await {
237-
return Some(path);
238-
}
230+
if let Some(stdout) = SystemCommandRunner.run("composer", &["global", "config", "home"]) {
231+
if let Some(path) = parse_composer_home_output(&stdout) {
232+
if is_dir(&path).await {
233+
return Some(path);
239234
}
240235
}
241236
}

crates/socket-patch-core/src/package_json/find.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22
use tokio::fs;
33

44
use super::detect::PackageManager;
5+
use crate::utils::fs::{entry_file_type, is_dir, list_dir_entries};
56

67
/// Detect the package manager based on lockfiles in the project root.
78
/// Checks for pnpm-lock.yaml, pnpm-lock.yml, and pnpm-workspace.yaml.
@@ -346,12 +347,7 @@ fn is_ignored_dir(name: &str) -> bool {
346347

347348
/// Search one level deep for package.json files.
348349
async fn search_one_level(dir: &Path, results: &mut Vec<PathBuf>) {
349-
let mut entries = match fs::read_dir(dir).await {
350-
Ok(e) => e,
351-
Err(_) => return,
352-
};
353-
354-
while let Ok(Some(entry)) = entries.next_entry().await {
350+
for entry in list_dir_entries(dir).await {
355351
let path = entry.path();
356352
// A single-level `dir/*` glob follows a symlinked direct member, the
357353
// way npm/pnpm (and our cargo `glob_dir`) resolve a workspace member
@@ -361,11 +357,7 @@ async fn search_one_level(dir: &Path, results: &mut Vec<PathBuf>) {
361357
// recursive searcher below deliberately does NOT follow symlinks,
362358
// to avoid loops/escapes — there a symlink's `is_dir() == false` is the
363359
// desired skip.)
364-
if !fs::metadata(&path)
365-
.await
366-
.map(|m| m.is_dir())
367-
.unwrap_or(false)
368-
{
360+
if !is_dir(&path).await {
369361
continue;
370362
}
371363
// A `dir/*` pattern must not pick up node_modules/hidden/output dirs as
@@ -388,15 +380,9 @@ async fn search_recursive(dir: &Path, depth: usize, max_depth: usize, results: &
388380
return;
389381
}
390382

391-
let mut entries = match fs::read_dir(dir).await {
392-
Ok(e) => e,
393-
Err(_) => return,
394-
};
395-
396-
while let Ok(Some(entry)) = entries.next_entry().await {
397-
let ft = match entry.file_type().await {
398-
Ok(ft) => ft,
399-
Err(_) => continue,
383+
for entry in list_dir_entries(dir).await {
384+
let Some(ft) = entry_file_type(&entry).await else {
385+
continue;
400386
};
401387
if !ft.is_dir() {
402388
continue;

crates/socket-patch-core/src/patch/vendor/bun_lock.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use crate::patch::copy_tree::remove_tree;
4141
use crate::utils::fs::atomic_write_bytes;
4242

4343
use super::common::{already_patched_result, refused};
44-
use super::npm_common::{done_failure, guard_coordinates, stage_patch_pack};
45-
use super::path::{parse_vendor_path, vendor_uuid_dir_rel};
44+
use super::npm_common::{done_failure, guard_coordinates, guard_revert_uuid_dir, stage_patch_pack};
45+
use super::path::parse_vendor_path;
4646
use super::state::{
4747
write_marker, VendorArtifact, VendorEntry, VendorMarker, WiringAction, WiringRecord,
4848
};
@@ -274,11 +274,9 @@ pub(crate) async fn revert_bun(
274274
// SECURITY: `entry.uuid` comes from the committed, tamper-able
275275
// state.json and names the directory tree we are about to DELETE.
276276
// Validate through the same fail-closed grammar vendor used.
277-
let Some(uuid_dir_rel) = vendor_uuid_dir_rel("npm", &entry.uuid) else {
278-
return RevertOutcome::failed(format!(
279-
"refusing revert: `{}` is not a canonical patch uuid (tampered state.json?)",
280-
entry.uuid
281-
));
277+
let uuid_dir_rel = match guard_revert_uuid_dir(&entry.uuid) {
278+
Ok(d) => d,
279+
Err(outcome) => return outcome,
282280
};
283281
if dry_run {
284282
return RevertOutcome::ok();

crates/socket-patch-core/src/patch/vendor/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async fn cargo_service_copy(
123123
CargoServiceCopy::FallBack
124124
}
125125
};
126-
match fetch_verified_archive(cfg, &record.uuid, name).await {
126+
match fetch_verified_archive(cfg, &record.uuid).await {
127127
ServiceArtifact::Ready(archive) => {
128128
// Clean copy dir, then extract the `.crate` (tar.gz; strip its
129129
// single `{name}-{version}/` top-level dir) into it.

crates/socket-patch-core/src/patch/vendor/composer_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ async fn composer_service_copy(
490490
ComposerServiceCopy::FallBack
491491
}
492492
};
493-
match fetch_verified_archive(cfg, &record.uuid, pkg).await {
493+
match fetch_verified_archive(cfg, &record.uuid).await {
494494
ServiceArtifact::Ready(archive) => {
495495
let _ = remove_tree(copy_dir).await;
496496
if let Err(e) = tokio::fs::create_dir_all(copy_dir).await {

crates/socket-patch-core/src/patch/vendor/gem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ async fn gem_service_copy(
578578
};
579579

580580
// Step 1: the prebuilt `.gem` (sha512-verified against the reference).
581-
let archive = match fetch_verified_archive(cfg, &record.uuid, name).await {
581+
let archive = match fetch_verified_archive(cfg, &record.uuid).await {
582582
ServiceArtifact::Ready(archive) => archive,
583583
ServiceArtifact::IntegrityMismatch(reason) => {
584584
return miss(
@@ -613,7 +613,7 @@ async fn gem_service_copy(
613613
};
614614

615615
// Step 2: the stub gemspec the converter generated alongside the `.gem`.
616-
let stub = match fetch_verified_secondary(cfg, &archive, GEM_STUB_ARTIFACT_KIND, name).await {
616+
let stub = match fetch_verified_secondary(cfg, &archive, GEM_STUB_ARTIFACT_KIND).await {
617617
SecondaryArtifactResult::Ready(bytes) => bytes,
618618
SecondaryArtifactResult::Absent => {
619619
return miss(

crates/socket-patch-core/src/patch/vendor/golang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ async fn go_service_redirect(
369369
GoServiceRedirect::FallBack
370370
}
371371
};
372-
match fetch_verified_archive(cfg, &record.uuid, module).await {
372+
match fetch_verified_archive(cfg, &record.uuid).await {
373373
ServiceArtifact::Ready(archive) => {
374374
// Clean copy dir; extract the module zip (strip its literal
375375
// `{module}@{version}/` prefix) into it.

crates/socket-patch-core/src/patch/vendor/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ mod pypi_wheel;
7979
pub mod registry_fetch;
8080
pub(crate) mod service_fetch;
8181
mod toml_surgery;
82-
pub mod verify;
83-
pub mod yarn_berry_lock;
84-
pub mod yarn_classic_lock;
82+
pub(crate) mod verify;
83+
pub(crate) mod yarn_berry_lock;
84+
mod yarn_classic_lock;
8585

8686
pub use path::{ecosystem_dir_for_purl, parse_vendor_path};
8787
pub use state::{load_state, lookup_entry, save_state, VendorEntry, VendorState, VENDOR_STATE_REL};

0 commit comments

Comments
 (0)