Skip to content

Commit

Permalink
harden against invalid dataset directory state in reinstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxcapades committed Feb 16, 2024
1 parent 9af9953 commit 0d8fada
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class InstallStatus(val value: String) {
companion object {
@JvmStatic
fun fromString(value: String): InstallStatus {
for (enum in values())
for (enum in entries)
if (enum.value == value)
return enum

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ object DatasetReinstaller {

val directory = manager.getDatasetDirectory(dataset.owner, dataset.datasetID)

if (!directory.isReinstallable()) {
log.warn("skipping reinstall of dataset {}/{} into project {} due to the dataset directory being in an invalid state in the data store", dataset.owner, dataset.datasetID, projectID)
return
}

val response = withDataTar(directory) { dataTar ->
dataTar.inputStream()
.use { inp -> client.postInstallData(dataset.datasetID, projectID, inp) }
Expand All @@ -168,6 +173,28 @@ object DatasetReinstaller {
-> handleInstallUnexpectedError(response as InstallDataUnexpectedErrorResponse, dataset, projectID)
}
}

private fun DatasetDirectory.isReinstallable(): Boolean {
var ok = true

if (!hasMetaFile()) {
log.warn("dataset {}/{} has no meta file present in the data store", ownerID, datasetID)
ok = false
}

if (!hasManifestFile()) {
log.warn("dataset {}/{} has no manifest file present in the data store", ownerID, datasetID)
ok = false
}

if (!hasInstallReadyFile()) {
log.warn("dataset {}/{} has no install-ready file present in the data store", ownerID, datasetID)
ok = false
}

return ok
}

private fun <T> withDataTar(s3Dir: DatasetDirectory, fn: (Path) -> T): T {
TempFiles.withTempDirectory { tempDir ->
val tarFile = tempDir.resolve("dataset.tar.gz")
Expand Down

0 comments on commit 0d8fada

Please sign in to comment.