Skip to content

Commit ffe6c35

Browse files
committed
Do verify that the expected amount of bytes were written
Helpfully, Azure Pipelines reports an "artifact size", which is the total number of bytes to be extracted to disk. Since we had occasional problems due to incompletely downloaded/extracted artifacts (most lately, https://github.com/microsoft/git/runs/2218601656?check_suite_focus=true#step:3:9), let's make use of this to ensure that the expected number of bytes was written to disk. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c788f91 commit ffe6c35

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"Backoff",
1414
"MSYSTEM",
1515
"Pacman",
16+
"artifactsize",
1617
"autodrain",
1718
"unzipper",
1819
"vercel"

src/downloader.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function mkdirp(directoryPath: string): void {
3636

3737
async function unzip(
3838
url: string,
39+
bytesToExtract: number,
3940
stripPrefix: string,
4041
outputDirectory: string,
4142
verbose: boolean | number,
@@ -88,12 +89,21 @@ async function unzip(
8889
mkdirp(entryPath.replace(/\/$/, ''))
8990
entry.autodrain()
9091
} else {
91-
entry.pipe(fs.createWriteStream(`${entryPath}`))
92+
entry
93+
.pipe(fs.createWriteStream(`${entryPath}`))
94+
.on('finish', () => {
95+
bytesToExtract -= fs.statSync(entryPath).size
96+
})
9297
}
9398
})
9499
.on('error', reject)
95100
.on('finish', progress)
96-
.on('finish', resolve)
101+
.on('finish', () => {
102+
bytesToExtract === 0
103+
? resolve()
104+
: // eslint-disable-next-line prefer-promise-reject-errors
105+
reject(`${bytesToExtract} bytes left to extract`)
106+
})
97107
})
98108
.on('error', reject)
99109
})
@@ -231,7 +241,12 @@ export async function get(
231241
): Promise<void> => {
232242
const data2 = await fetchJSONFromURL<{
233243
count: number
234-
value: [{name: string; resource: {downloadUrl: string}}]
244+
value: [
245+
{
246+
name: string
247+
resource: {downloadUrl: string; properties: {artifactsize: number}}
248+
}
249+
]
235250
}>(`${baseURL}/${data.value[0].id}/artifacts`)
236251
const filtered = data2.value.filter(e => e.name === artifactName)
237252
if (filtered.length !== 1) {
@@ -240,11 +255,13 @@ export async function get(
240255
)
241256
}
242257
const url = filtered[0].resource.downloadUrl
258+
const bytesToExtract = filtered[0].resource.properties.artifactsize
243259
let delayInSeconds = 1
244260
for (;;) {
245261
try {
246262
await unzip(
247263
url,
264+
bytesToExtract,
248265
`${artifactName}/`,
249266
outputDirectory,
250267
verbose,

0 commit comments

Comments
 (0)