From: Steven Baltakatei Sandoval Date: Sat, 20 May 2023 22:23:19 +0000 (+0000) Subject: feat(user/bk-copy-rand-music):Restrict filenames of copied files X-Git-Tag: 0.8.2^2~11 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/4292743fe100a567fcdced502c499564dce707c3?ds=inline feat(user/bk-copy-rand-music):Restrict filenames of copied files - Note: Using `tr -dc '[:graph:][:space:]'` as character filter. --- diff --git a/user/bk-copy-rand-music b/user/bk-copy-rand-music index bc21e5b..b807286 100644 --- a/user/bk-copy-rand-music +++ b/user/bk-copy-rand-music @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Desc: Copies random audio files # Usage: bk-copy-rand-music [dir SOURCE] [dir DEST] [int DURATION] ([int BYTES]) -# Version: 0.1.1 +# Version: 0.2.0 # Depends: BK-2020-03: bkshuf v0.1.0 declare -Ag appRollCall # Associative array for storing app status @@ -516,13 +516,15 @@ main() { fpath="$(printf "%s" "$line" | cut -d',' -f3-)"; ## Get basename of path file_basename="$(basename "$fpath")"; + ### Get basename without unprintable non-ASCII characters + file_basename_compat="$(printf "%s" "$file_basename" | tr -dc '[:graph:][:space:]' )"; ## Get 16-character b2sum fingerprint (for different files that share basename) fingerprint="$(b2sum -l32 "$fpath" | awk '{print $1}' )"; ## Form output filename num="$(printf "$num_fmt" "$n")"; - file_name="$num"_"$fingerprint".."$file_basename"; + file_name="$num"_"$fingerprint".."$file_basename_compat"; file_name="${file_name:0:$max_filename_length}"; # Limit filename length (e.g. Windows has max of 255 characters) ## Form output path @@ -538,7 +540,7 @@ main() { printf "$log_fmt" "$num" "$fingerprint" "$fdur" "$fsize" "$fpath_can" >> "$path_log_output"; ((n++)); - unset file_basename path_output + unset file_basename file_basename_compat path_output; done < <(printf "%s\n" "${list_copy[@]}"); # Report total duration and size