Commit 2c00752
authored
Use Etc.nprocessors and handle sandboxed environments (#876)
## Summary
- Replace OS-specific `processor_count` implementation with Ruby's
`Etc.nprocessors`
- Rescue `Errno::EPERM`/`ENOENT` in `parent_command` when `ps` is
unavailable
## Motivation
The current `processor_count` method shells out to OS-specific commands
(`sysctl`, `/proc/cpuinfo`, `hwprefs`, etc.) to detect CPU count. This
was copied from the [parallel
gem](https://github.com/grosser/parallel/blob/v1.6.1/lib/parallel/processor_count.rb#L17-L51)
in 2015 when supporting older Ruby versions was necessary.
Ruby's `Etc.nprocessors` has been available since Ruby 2.2 (2014), and
overcommit requires Ruby 2.6+. It works cross-platform without shelling
out, which also fixes failures in sandboxed environments (e.g. macOS
Seatbelt) where `sysctl` calls are blocked at the syscall level —
causing `processor_count` to return 0 and breaking all hook validation.
Similarly, `parent_command` shells out to `ps` which can fail with
`Errno::EPERM` in sandboxed environments. The rescue returns `nil`,
which the caller (`amendment?`) already handles — hooks run against all
staged files instead of only amended ones.1 parent 11838c6 commit 2c00752
1 file changed
+6
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
| |||
212 | 216 | | |
213 | 217 | | |
214 | 218 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 219 | + | |
| 220 | + | |
249 | 221 | | |
250 | 222 | | |
251 | 223 | | |
| |||
0 commit comments