Skip to content

Commit

Permalink
Rename HashFailed to HashMismatch & clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Sep 25, 2024
1 parent bec3867 commit fdab827
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class ActionError(
class NoHashes(val projectFile: ProjectFile) :
ActionError("File '${projectFile.getPath()}' has no hashes.", isWarning = true)

class HashFailed(val projectFile: ProjectFile, val originalHash: String, val newHash: String) :
class HashMismatch(val projectFile: ProjectFile, val originalHash: String, val newHash: String) :
ActionError("""Failed to math hash for file '${projectFile.getPath()}'.
| Original hash: $originalHash
| New hash: $newHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,10 @@ suspend fun List<ProjectFile>.fetch(
return@launch
}

projectFile.checkIntegrity(bytes)?.let {
if (it !is NoHashes)
{
return@launch
}
projectFile.checkIntegrity(bytes)?.let { err ->
onError(err)

onError(it)
if (err is HashMismatch) return@launch
}

send(projectFile to bytes)
Expand Down Expand Up @@ -114,7 +111,9 @@ suspend fun deleteOldFiles(
val folder = Path(workingPath, projectType.folderName)
if (folder.notExists()) return@mapNotNull null
runCatching { folder.listDirectoryEntries() }.get()
}.flatten().forEach { file ->
}
.flatten()
.forEach { file ->
launch {
val bytes = runCatching { file.readBytes() }.get()
val fileHash = bytes?.let { createHash("sha1", it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import teksturepako.pakku.api.actions.ActionError
import teksturepako.pakku.api.actions.ActionError.HashFailed
import teksturepako.pakku.api.actions.ActionError.HashMismatch
import teksturepako.pakku.api.actions.ActionError.NoHashes
import teksturepako.pakku.api.data.LockFile
import teksturepako.pakku.api.data.workingPath
Expand Down Expand Up @@ -62,7 +62,7 @@ data class ProjectFile(

if (originalHash != newHash)
{
return HashFailed(this, originalHash, newHash)
return HashMismatch(this, originalHash, newHash)
}
else continue
}
Expand Down

0 comments on commit fdab827

Please sign in to comment.