mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
fix: convert Windows CRLF line endings to LF for downloaded files
This commit is contained in:
@@ -1307,6 +1307,7 @@ import_domains_or_subnets_from_remote_file() {
|
||||
http_proxy_address="$(get_service_proxy_address)"
|
||||
|
||||
download_to_file "$url" "$tmpfile" "$http_proxy_address"
|
||||
convert_crlf_to_lf "$tmpfile"
|
||||
|
||||
if [ $? -ne 0 ] || [ ! -s "$tmpfile" ]; then
|
||||
log "Download $url list failed" "error"
|
||||
|
||||
@@ -305,10 +305,17 @@ download_to_file() {
|
||||
log "Attempt $attempt/$retries to download $url failed" "warn"
|
||||
sleep "$wait"
|
||||
done
|
||||
}
|
||||
|
||||
# Converts Windows-style line endings (CRLF) to Unix-style (LF)
|
||||
convert_crlf_to_lf() {
|
||||
local filepath="$1"
|
||||
|
||||
if grep -q $'\r' "$filepath"; then
|
||||
log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)"
|
||||
sed -i 's/\r$//' "$filepath"
|
||||
log "Downloaded file has Windows line endings (CRLF). Converting to Unix (LF)" "debug"
|
||||
local tmpfile
|
||||
tmpfile=$(mktemp)
|
||||
tr -d '\r' < "$filepath" > "$tmpfile" && mv "$tmpfile" "$filepath"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user