fix: convert Windows CRLF line endings to LF for downloaded files

This commit is contained in:
Andrey Petelin
2025-10-29 21:36:46 +05:00
parent d09fdc0b95
commit fe84b3154f
2 changed files with 10 additions and 2 deletions

View File

@@ -1307,6 +1307,7 @@ import_domains_or_subnets_from_remote_file() {
http_proxy_address="$(get_service_proxy_address)" http_proxy_address="$(get_service_proxy_address)"
download_to_file "$url" "$tmpfile" "$http_proxy_address" download_to_file "$url" "$tmpfile" "$http_proxy_address"
convert_crlf_to_lf "$tmpfile"
if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then
log "Download $url list failed" "error" log "Download $url list failed" "error"

View File

@@ -305,10 +305,17 @@ download_to_file() {
log "Attempt $attempt/$retries to download $url failed" "warn" log "Attempt $attempt/$retries to download $url failed" "warn"
sleep "$wait" sleep "$wait"
done done
}
# Converts Windows-style line endings (CRLF) to Unix-style (LF)
convert_crlf_to_lf() {
local filepath="$1"
if grep -q $'\r' "$filepath"; then if grep -q $'\r' "$filepath"; then
log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)" log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)" "debug"
sed -i 's/\r$//' "$filepath" local tmpfile
tmpfile=$(mktemp)
tr -d '\r' < "$filepath" > "$tmpfile" && mv "$tmpfile" "$filepath"
fi fi
} }