mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 11:36:50 +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)"
|
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"
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user