Skip to content

Commit c62c119

Browse files
committed
Added gates so that resources module doesn't break windows
1 parent 4672706 commit c62c119

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

Pipfile.lock

Lines changed: 0 additions & 20 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.11"
9+
version = "2.2.12"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.11'
2+
__version__ = '2.2.12'

socketsecurity/core/resource_utils.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
"""
22
System resource utilities for the Socket Security CLI.
33
"""
4-
import resource
54
import logging
5+
import sys
6+
7+
# The resource module is only available on Unix-like systems
8+
resource_available = False
9+
try:
10+
import resource
11+
resource_available = True
12+
except ImportError:
13+
# On Windows, the resource module is not available
14+
pass
615

716
log = logging.getLogger("socketdev")
817

918

1019
def get_file_descriptor_limit():
1120
"""
1221
Get the current file descriptor limit (equivalent to ulimit -n)
13-
22+
1423
Returns:
15-
tuple: (soft_limit, hard_limit) or (None, None) if error
24+
tuple: (soft_limit, hard_limit) or (None, None) if error or on Windows
1625
"""
26+
if not resource_available:
27+
# On Windows, resource module is not available
28+
return None, None
29+
1730
try:
1831
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
1932
return soft_limit, hard_limit
@@ -25,26 +38,26 @@ def get_file_descriptor_limit():
2538
def check_file_count_against_ulimit(file_count, buffer_size=100):
2639
"""
2740
Check if the number of files would exceed the file descriptor limit
28-
41+
2942
Args:
3043
file_count (int): Number of files to check
3144
buffer_size (int): Safety buffer to leave for other file operations
32-
45+
3346
Returns:
3447
dict: Information about the check
3548
"""
3649
soft_limit, hard_limit = get_file_descriptor_limit()
37-
50+
3851
if soft_limit is None:
3952
return {
4053
"can_check": False,
4154
"error": "Could not determine file descriptor limit",
4255
"safe_to_process": True # Assume safe if we can't check
4356
}
44-
57+
4558
available_fds = soft_limit - buffer_size
4659
would_exceed = file_count > available_fds
47-
60+
4861
return {
4962
"can_check": True,
5063
"file_count": file_count,

0 commit comments

Comments
 (0)