Skip to content

Commit 675c58a

Browse files
committed
Address review comments
1 parent edad43e commit 675c58a

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/backend/utils.ts

+34-25
Original file line numberDiff line numberDiff line change
@@ -1080,31 +1080,40 @@ export async function moveOnUnix(
10801080
let percent = 0
10811081
let eta = ''
10821082
let bytes = '0'
1083-
// Rsync outputs either the file currently being transferred or a
1084-
// progress report. To know which one of those `data` is, we check if
1085-
// it includes a %, :, and starts with a space
1086-
// If all of these aren't the case, it's *most likely* a filename
1087-
// FIXME: This is pretty hacky, but I don't see an obvious way to
1088-
// "divide" the two output types other than that
1089-
const isFilenameOutput =
1090-
!data.includes('%') && !data.includes(':') && !data.startsWith(' ')
1091-
1092-
if (isFilenameOutput) {
1093-
// If we have a filename output, we've started copying a new
1094-
// file (we thus start at 0%, with 0 bytes moved, and with no ETA)
1095-
1096-
// Data will be a multiline string, potentially with directory names,
1097-
// finally the file name, and ending with an empty line
1098-
currentFile = data.trim().split('\n').at(-1)!
1099-
} else {
1100-
// If we got the progress update, try to read out the bytes, ETA and
1101-
// percent
1102-
const bytesMatch = data.match(/^\s*(\d+)/)?.[1]
1103-
const etaMatch = data.match(/(\d+:\d+:\d+)/)?.[1]
1104-
const percentMatch = data.match(/(\d+)%/)?.[1]
1105-
if (bytesMatch) bytes = getFileSize(Number(bytesMatch))
1106-
if (etaMatch) eta = etaMatch
1107-
if (percentMatch) percent = Number(percentMatch)
1083+
1084+
// Multiple output lines might be buffered into a single `data`, so
1085+
// we have to iterate over every line (we can't just look at the last
1086+
// one since that might skip new files)
1087+
for (const outLine of data.trim().split('\n')) {
1088+
// Rsync outputs either the file currently being transferred or a
1089+
// progress report. To know which one of those `outLine` is, we check
1090+
// if it includes a %, :, and starts with a space
1091+
// If all of these aren't the case, it's *most likely* a filename
1092+
// FIXME: This is pretty hacky, but I don't see an obvious way to
1093+
// "divide" the two output types other than that
1094+
const isFilenameOutput =
1095+
!outLine.includes('%') &&
1096+
!outLine.includes(':') &&
1097+
!outLine.startsWith(' ')
1098+
1099+
if (isFilenameOutput) {
1100+
// If we have a filename output, set `lastFile` and reset all
1101+
// other metrics. Either there'll be a progress update in the next
1102+
// line of `data`, or we've just started copying and thus start at 0
1103+
currentFile = outLine
1104+
percent = 0
1105+
eta = ''
1106+
bytes = '0'
1107+
} else {
1108+
// If we got the progress update, try to read out the bytes, ETA and
1109+
// percent
1110+
const bytesMatch = outLine.match(/^\s+(\d+)/)?.[1]
1111+
const etaMatch = outLine.match(/(\d+:\d{2}:\d{2})/)?.[1]
1112+
const percentMatch = outLine.match(/(\d+)%/)?.[1]
1113+
if (bytesMatch) bytes = getFileSize(Number(bytesMatch))
1114+
if (etaMatch) eta = etaMatch
1115+
if (percentMatch) percent = Number(percentMatch)
1116+
}
11081117
}
11091118

11101119
sendFrontendMessage(`progressUpdate-${gameInfo.app_name}`, {

0 commit comments

Comments
 (0)