Skip to content

Commit

Permalink
Stop using MediaFile#hashWithPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Nov 25, 2021
1 parent 3ca5095 commit 3e439e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void downloadMediaFiles(String tempMediaPath, FormDownloaderListener sta
writeFile(mediaFile, tempMediaFile, tempDir, stateListener);
} else {
String currentFileHash = Md5.getMd5Hash(finalMediaFile);
String downloadFileHash = validateHash(toDownload.getHashWithPrefix());
String downloadFileHash = validateHash(toDownload.getHash());

if (currentFileHash != null && downloadFileHash != null && !currentFileHash.contentEquals(downloadFileHash)) {
// if the hashes match, it's the same file otherwise replace it with the new one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ open class ServerFormsDetailsFetcher(
return true
}

val mediaFileHash = newMediaFile.hashWithPrefix.let { it.substring(4, it.length) }
return localMediaFiles.any {
mediaFileHash == getMd5Hash(it)
newMediaFile.hash == getMd5Hash(it)
}
}
}
7 changes: 5 additions & 2 deletions forms/src/main/java/org/odk/collect/forms/MediaFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package org.odk.collect.forms

data class MediaFile(
val filename: String,
val hashWithPrefix: String,
private val hashWithPrefix: String,
val downloadUrl: String
)
) {

val hash = hashWithPrefix.substring("md5:".length)
}

0 comments on commit 3e439e3

Please sign in to comment.