Skip to content

Commit

Permalink
Add test for v3 send files
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Jul 13, 2024
1 parent 862c30e commit 5de3f34
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
4 changes: 3 additions & 1 deletion tests/scripts/2.4.1_send_files_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ files=(
'資料夾 2/子資料夾 2/文字檔案 8.txt'
)

. scripts/common/2.4.x_send_files_v2.sh
proto="$PROTO_V2"

. scripts/common/x.4.x_send_files.sh
4 changes: 3 additions & 1 deletion tests/scripts/2.4_send_files_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ files=(
'sub 1/subsub_2/file_8.txt'
)

. scripts/common/2.4.x_send_files_v2.sh
proto="$PROTO_V2"

. scripts/common/x.4.x_send_files.sh
18 changes: 18 additions & 0 deletions tests/scripts/3.4.1_send_files_v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

files=(
'文字檔案 1.txt'
'另一個文件_2.txt'
'空的/'
'資料夾_1/文字檔案 3.txt'
'資料夾_1/另一個文件 4.txt'
'資料夾 2/文字檔案 5.txt'
'資料夾 2/空的/'
'資料夾 2/子資料夾/文字檔案 6.txt'
'資料夾 2/子資料夾/另一個文件_7.txt'
'資料夾 2/子資料夾 2/空的/'
)

proto="$PROTO_V3"

. scripts/common/x.4.x_send_files.sh
18 changes: 18 additions & 0 deletions tests/scripts/3.4_send_files_v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

files=(
'file 1.txt'
'file_2.txt'
'empty/'
'sub/file 3.txt'
'sub/file 4.txt'
'sub 1/file 5.txt'
'sub 1/empty 1/'
'sub 1/subsub/file 6.txt'
'sub 1/subsub/file_7.txt'
'sub 1/subsub_2/empty 2/'
)

proto="$PROTO_V3"

. scripts/common/x.4.x_send_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@ for f in "${files[@]}"; do
if [[ $f == */* ]]; then
mkdir -p "${f%/*}"
fi
echo "$f"$'\n''abc' >"$f"
if [[ $f != */ ]]; then
echo "$f"$'\n''abc' >"$f"
fi
done

chunks=''

appendToChunks() {
fname="$1"
for fname in "${files[@]}"; do
printf -v _ '%s%n' "$fname" utf8nameLen
nameLength="$(printf '%016x' $utf8nameLen)"
if [ -d "$fname" ]; then
for f in "$fname"/*; do
appendToChunks "$f"
done
elif [ -f "$fname" ]; then
printf -v _ '%s%n' "$fname" utf8nameLen
nameLength="$(printf '%016x' $utf8nameLen)"
fileSize=$(printf '%016x' $(stat -c '%s' "$fname"))
fileSize=-1
content=''
else
fileSize="$(stat -c '%s' "$fname")"
content=$(cat "$fname" | bin2hex | tr -d '\n')
chunks+="${nameLength}$(echo -n "$fname" | bin2hex)${fileSize}${content}"
fi
}

for f in *; do
appendToChunks "$f"
fileSize16=$(printf '%016x' "$fileSize")
chunks+="${nameLength}$(echo -n "$fname" | bin2hex)${fileSize16}${content}"
done

cd ..
mkdir -p copies
update_config working_dir copies

proto="$PROTO_V2"
method="$METHOD_SEND_FILES"
fileCount=$(printf '%016x' $(echo -n "${#files[@]}"))

Expand Down

0 comments on commit 5de3f34

Please sign in to comment.