Added logic to check if artifact to-be-downloaded does not exceed defined disc space threshold
This commit is contained in:
@@ -74,9 +74,24 @@ async function doImport (owner, repo, id) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// choose latest artifact
|
// choose latest artifact
|
||||||
|
currUsage, threshold = fs.statfs("/", (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Failure getting filesystem statistics!")
|
||||||
|
}
|
||||||
|
usedBlocks = (stats.blocks - stats.bfree)
|
||||||
|
usedBytes = usedBlocks * stats.bsize
|
||||||
|
threshold = stats.blocks * stats.bsize * 0.95
|
||||||
|
return (usedBytes, threshold)
|
||||||
|
});
|
||||||
const artifact = artifacts.data.artifacts
|
const artifact = artifacts.data.artifacts
|
||||||
.reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc)
|
.reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc)
|
||||||
artifactId = artifact.id
|
artifactId = artifact.id
|
||||||
|
// Check that size of artifact does not exceed disc space maximum.
|
||||||
|
artifactSize = artifact.size_in_bytes
|
||||||
|
if (currUsage + artifactSize >= threshold) {
|
||||||
|
console.error(`File (${artifactSize}) is exceeding allocated game memory of ${threshold}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
const url = artifact.archive_download_url
|
const url = artifact.archive_download_url
|
||||||
// Make sure the download folder exists
|
// Make sure the download folder exists
|
||||||
if (!fs.existsSync(path.join(__dirname, "..", "games"))){
|
if (!fs.existsSync(path.join(__dirname, "..", "games"))){
|
||||||
|
|||||||
Reference in New Issue
Block a user