Skip to content

Commit e5f16f5

Browse files
committed
Feature: Checks on PATHs and restricted environments.
1 parent 831b073 commit e5f16f5

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

humble.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ def get_analysis_results():
430430

431431

432432
def save_analysis_results(t_cnt):
433+
if not validate_history_file():
434+
return ("Not available",) * 6
433435
with open(HUMBLE_FILES[0], 'a+', encoding='utf8') as all_analysis:
434436
all_analysis.seek(0)
435437
url_ln = [line for line in all_analysis if URL in line]
@@ -468,6 +470,8 @@ def compare_analysis_results(*analysis_totals, en_cnt, m_cnt, f_cnt, i_cnt,
468470
e_cnt, t_cnt):
469471
if analysis_totals[0] == "First":
470472
return [get_detail('[first_analysis]', replace=True)] * 6
473+
elif analysis_totals[0] == "Not available":
474+
return [get_detail('[notaval_analysis]', replace=True)] * 6
471475
current = [int(val) for val in analysis_totals]
472476
differences = [en_cnt, m_cnt, f_cnt, i_cnt[0], e_cnt, t_cnt]
473477
return [get_detail('[no_changes]', replace=True) if (d - c) == 0
@@ -1477,23 +1481,37 @@ def check_input_traversal(user_input):
14771481
sys.exit()
14781482

14791483

1480-
def check_path_permissions(output_path):
1484+
def validate_path(output_path):
1485+
# Validates if there are errors with the supplied path.
14811486
try:
1482-
open(path.join(output_path, HUMBLE_FILES[1]), 'w')
1483-
except PermissionError:
1484-
print(f"\n {get_detail('[args_nowr]', replace=True)} \
1485-
('{output_path}')")
1487+
with open(path.join(output_path, HUMBLE_FILES[1]), 'w'):
1488+
pass
1489+
except OSError as e:
1490+
print(f"\n {get_detail('[args_pathe]', replace=True)} '{output_path}' \
1491+
({e.strerror})")
14861492
sys.exit()
14871493
else:
14881494
remove(path.join(output_path, HUMBLE_FILES[1]))
14891495

14901496

1497+
def validate_history_file():
1498+
# Validates if the analysis history file (analysis_h.txt) can be created in
1499+
# the current path, avoiding errors in restricted filesystems such as
1500+
# those used by AI like 'gemini-cli'.
1501+
try:
1502+
with open(path.join(OS_PATH, HUMBLE_FILES[0]), 'a+', encoding='utf8'):
1503+
pass
1504+
except OSError:
1505+
return False
1506+
return True
1507+
1508+
14911509
def check_output_path(args, output_path):
14921510
check_input_traversal(args.output_path)
14931511
if args.output is None:
14941512
print_error_detail('[args_nooutputfmt]')
14951513
elif path.exists(output_path):
1496-
check_path_permissions(output_path)
1514+
validate_path(output_path)
14971515
else:
14981516
print(f"\n {get_detail('[args_noexportpath]', replace=True)} \
14991517
('{output_path}')")

l10n/details.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ HTTP Response Headers
15671567
[first_analysis]
15681568
First Analysis
15691569

1570+
[notaval_analysis]
1571+
Not available
1572+
15701573
[no_changes]
15711574
No changes
15721575

@@ -1874,8 +1877,8 @@ Error: Remove these HTTP headers from the '-s' parameter as they are not analyze
18741877
[args_noexportpath]
18751878
Error: The indicated PATH does not exist
18761879

1877-
[args_nowr]
1878-
Error: This user does not have write permissions on the indicated PATH
1880+
[args_pathe]
1881+
Error: Cannot use the PATH
18791882

18801883
[args_input_traversal]
18811884
Error: The indicated filename, or absolute path, seem wrong

l10n/details_es.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,9 @@ Cabeceras de respuesta HTTP
15681568
[first_analysis]
15691569
Primer análisis
15701570

1571+
[notaval_analysis]
1572+
No disponible
1573+
15711574
[no_changes]
15721575
Sin cambios
15731576

@@ -1875,8 +1878,8 @@ Error: El parámetro '-op' requiere el parámetro '-o'.
18751878
[args_noexportpath]
18761879
Error: No existe la ruta indicada
18771880

1878-
[args_nowr]
1879-
Erorr: Este usuario no tiene permisos de escritura en la ruta indicada
1881+
[args_pathe]
1882+
Error: No se puede usar la ruta
18801883

18811884
[args_input_traversal]
18821885
Error: El nombre del fichero, o la ruta absoluta, indicados parecen erróneos

0 commit comments

Comments
 (0)