1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 04:49:17 +00:00

Fix optimize compatibility at some times

This commit is contained in:
Tw93
2025-12-03 13:56:14 +08:00
parent 5fce82719f
commit a5c5a8d7af
3 changed files with 15 additions and 6 deletions

View File

@@ -98,13 +98,17 @@ readonly STAT_BSD="/usr/bin/stat"
# Get file size in bytes using BSD stat
get_file_size() {
local file="$1"
$STAT_BSD -f%z "$file" 2> /dev/null || echo 0
local result
result=$($STAT_BSD -f%z "$file" 2> /dev/null)
echo "${result:-0}"
}
# Get file modification time (epoch seconds) using BSD stat
get_file_mtime() {
local file="$1"
$STAT_BSD -f%m "$file" 2> /dev/null || echo 0
local result
result=$($STAT_BSD -f%m "$file" 2> /dev/null)
echo "${result:-0}"
}
# Get file owner username using BSD stat
@@ -1145,7 +1149,9 @@ clean_tool_cache() {
# Returns: size in KB, or 0 if path doesn't exist or error occurs
get_path_size_kb() {
local path="$1"
du -sk "$path" 2> /dev/null | awk '{print $1}' || echo "0"
local result
result=$(du -sk "$path" 2> /dev/null | awk '{print $1}')
echo "${result:-0}"
}
bytes_to_human_kb() { bytes_to_human "$((${1:-0} * 1024))"; }