Skip to content

Commit 3bc4379

Browse files
authored
Properly fix #7
1 parent 073ce9e commit 3bc4379

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

prsync

+11-10
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ NC='\033[0m' # No Color
2525

2626
if ! command -v parallel &> /dev/null
2727
then
28-
echo -e "${RED}parallel could not be found${NC}"
29-
exit
28+
echo -e "${RED}parallel could not be found${NC}"
29+
exit
3030
fi
3131

3232
if [[ "$1" == --parallel=* ]]; then
33-
PARALLEL_RSYNC="${1##*=}"
34-
shift
33+
PARALLEL_RSYNC="${1##*=}"
34+
shift
3535
else
36-
PARALLEL_RSYNC=$(nproc 2> /dev/null || echo 10)
36+
PARALLEL_RSYNC=$(nproc 2> /dev/null || echo 10)
3737
fi
3838
echo -e "${GREEN}INFO: Using up to ${PARALLEL_RSYNC} processes for transfer ...${NC}"
3939

@@ -42,7 +42,8 @@ trap 'rm -rf "${TMPDIR}"' EXIT
4242

4343
echo -e "${GREEN}INFO: Determining file list for transfer ...${NC}"
4444
# sorted by size (descending)
45-
rsync "$@" --out-format="%l %n" --no-v --quiet --dry-run 2> /dev/null \
45+
rsync "$@" --out-format="%l %n" --no-v --dry-run 2> /dev/null \
46+
| grep -v "sending incremental file list" \
4647
| sort --numeric-sort --reverse \
4748
> "${TMPDIR}/files.all"
4849

@@ -51,8 +52,8 @@ TOTAL_FILES=$(wc -l < "${TMPDIR}/files.all")
5152
TOTAL_SIZE=$(awk '{ts+=$1}END{printf "%.0f", ts}' < "${TMPDIR}/files.all")
5253
echo -e "${GREEN}INFO: ${TOTAL_FILES} ($(( TOTAL_SIZE/1024**2 )) MB) files to transfer.${NC}"
5354
if [ "${TOTAL_FILES}" -eq "0" ]; then
54-
echo -e "${ORANGE}WARN: Nothing to transfer :)${NC}"
55-
exit 0
55+
echo -e "${ORANGE}WARN: Nothing to transfer :)${NC}"
56+
exit 0
5657
fi
5758

5859
function array_min {
@@ -77,7 +78,7 @@ function array_min {
7778
echo -e "${GREEN}INFO: Distributing files among chunks ...${NC}"
7879
# declare chunk-size array
7980
for ((I = 0 ; I < PARALLEL_RSYNC ; I++ )); do
80-
CHUNKS["${I}"]=0
81+
CHUNKS["${I}"]=0
8182
done
8283

8384
# add each file to the emptiest chunk, so they're as balanced by size as possible
@@ -104,7 +105,7 @@ for ((I = 1 ; I < PARALLEL_RSYNC ; I+=2 )); do
104105
continue
105106
fi
106107

107-
tac "${TMPDIR}/chunk.${I}" > "${TMPDIR}/chunk.${I}.r" && mv "${TMPDIR}/chunk.${I}.r" "${TMPDIR}/chunk.${I}"
108+
tac "${TMPDIR}/chunk.${I}" > "${TMPDIR}/chunk.${I}.r" && mv "${TMPDIR}/chunk.${I}.r" "${TMPDIR}/chunk.${I}"
108109
done
109110

110111
echo -e "${GREEN}DONE (${SECONDS}s)${NC}"

0 commit comments

Comments
 (0)