Remove under_base function from species_tools.php

Removed the under_base function to simplify path checks.
This commit is contained in:
Alexandre
2025-12-16 19:09:39 +01:00
committed by Nachtzuster
parent 7a17fa2574
commit 524d366023
+1 -12
View File
@@ -57,17 +57,6 @@ $sf_thresh = isset($config['SF_THRESH']) ? (float)$config['SF_THRESH'] : 0.0;
/* ---------- helpers ---------- */ /* ---------- helpers ---------- */
function join_path(...$parts): string { return preg_replace('#/+#', '/', implode('/', $parts)); } function join_path(...$parts): string { return preg_replace('#/+#', '/', implode('/', $parts)); }
function can_unlink(string $p): bool { return is_link($p) || is_file($p); } function can_unlink(string $p): bool { return is_link($p) || is_file($p); }
function under_base(string $path, string $base): bool {
if ($base === false) return false;
$baseReal = rtrim(realpath($base) ?: $base, DIRECTORY_SEPARATOR);
$resolved = realpath($path);
if ($resolved === false) {
$parent = realpath(dirname($path));
if ($parent === false) return false;
$resolved = $parent . DIRECTORY_SEPARATOR . basename($path);
}
return $resolved === $baseReal || strpos($resolved, $baseReal . DIRECTORY_SEPARATOR) === 0;
}
/* Collect files/dirs for a species */ /* Collect files/dirs for a species */
function collect_species_targets(SQLite3 $db, string $species, string $home, $base): array { function collect_species_targets(SQLite3 $db, string $species, string $home, $base): array {
@@ -89,7 +78,7 @@ function collect_species_targets(SQLite3 $db, string $species, string $home, $ba
$d = realpath(dirname($c)); $d = realpath(dirname($c));
if ($d !== false) { if ($d !== false) {
$alt = $d . DIRECTORY_SEPARATOR . basename($c); $alt = $d . DIRECTORY_SEPARATOR . basename($c);
if (can_unlink($alt) && under_base($alt, $base)) { $files[$alt] = true; $dirs[] = dirname($alt); } if (can_unlink($alt)) { $files[$alt] = true; $dirs[] = dirname($alt); }
} }
} }
} }