Skip to content

Commit 1251aed

Browse files
committed
style: collapse nested if statements using let chains in sandbox
Fix 4 clippy warnings by collapsing nested if/if-let statements into single if conditions using && with let chains. This improves code clarity and satisfies cargo clippy -D warnings.
1 parent ebb426b commit 1251aed

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

crates/sandbox/src/linux.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub fn apply_sandbox(policy: &SandboxPolicy) -> Result<(), String> {
1616
}
1717

1818
// 3. Apply seccomp network deny filter (must be last)
19-
if policy.network == NetworkPolicy::Deny {
20-
if let Err(e) = apply_seccomp_network_deny() {
21-
eprintln!("localgpt-sandbox: seccomp not applied: {}", e);
22-
}
19+
if policy.network == NetworkPolicy::Deny
20+
&& let Err(e) = apply_seccomp_network_deny()
21+
{
22+
eprintln!("localgpt-sandbox: seccomp not applied: {}", e);
2323
}
2424

2525
Ok(())
@@ -67,26 +67,26 @@ fn apply_landlock(policy: &SandboxPolicy) -> Result<(), String> {
6767

6868
// Read-only paths (system dirs)
6969
for path in &policy.read_only_paths {
70-
if path.exists() {
71-
if let Ok(fd) = PathFd::new(path) {
72-
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, read_access));
73-
}
70+
if path.exists()
71+
&& let Ok(fd) = PathFd::new(path)
72+
{
73+
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, read_access));
7474
}
7575
}
7676

7777
// Workspace — read+write
78-
if policy.workspace_path.exists() {
79-
if let Ok(fd) = PathFd::new(&policy.workspace_path) {
80-
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, write_access));
81-
}
78+
if policy.workspace_path.exists()
79+
&& let Ok(fd) = PathFd::new(&policy.workspace_path)
80+
{
81+
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, write_access));
8282
}
8383

8484
// Extra writable paths (/tmp, user-configured)
8585
for path in &policy.extra_write_paths {
86-
if path.exists() {
87-
if let Ok(fd) = PathFd::new(path) {
88-
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, write_access));
89-
}
86+
if path.exists()
87+
&& let Ok(fd) = PathFd::new(path)
88+
{
89+
let _ = (&mut ruleset).add_rule(PathBeneath::new(fd, write_access));
9090
}
9191
}
9292

0 commit comments

Comments
 (0)