Skip to content

Commit

Permalink
Fix unique fingerprint for wave bundle resources
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Feb 18, 2023
1 parent cf3fd74 commit b59fa72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,22 @@ class ResourcesBundle {

private List fileMeta(String name, Path file) {
final attrs = Files.readAttributes(file, BasicFileAttributes)
final regular = attrs.isRegularFile()
final meta = [
name,
attrs.isRegularFile() ? attrs.size() : 0,
attrs.lastModifiedTime().toMillis(),
regular ? attrs.size() : 0,
regular ? md5(file, attrs) : 0,
Integer.toOctalString(file.getPermissionsMode()) ]
log.trace "Module bundle entry=$meta"
return meta
}

private String md5(Path path, BasicFileAttributes attrs) {
return attrs.size() <= MAX_FILE_SIZE.bytes
? Files.readAllBytes(path).md5()
: '0'
}

String fingerprint() {
final allMeta = new ArrayList()
for( String name : getEntries() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ResourcesBundleTest extends Specification {
'this/that/ciao.txt' ] as Set

and:
bundle.fingerprint() == 'c063b8f42cfd65f4eb8efe7c30c108bc'
bundle.fingerprint() == '7404949a73f1707e39f641d9a54261ae'

}

Expand All @@ -99,19 +99,19 @@ class ResourcesBundleTest extends Specification {
bundle
!bundle.hasEntries()
and:
bundle.fingerprint() == 'c8597047abea34f987e6a347dca36823'
bundle.fingerprint() == 'c5e75f95b68f5119debd926961ef6abd'

when:
// changing file permissions, change the fingerprint
dockerPath.setPermissions(6,0,0)
then:
bundle.fingerprint() == '280d52c24debce950148f4250a34e3ff'
bundle.fingerprint() == '7b2200ff24230f76cea22e5eb15b1701'

when:
// changing the last modified time, change the fingerprint
dockerPath.setLastModified(LAST_MODIFIED +100)
then:
bundle.fingerprint() == '41bd15592039e3a198bef861800d3cd6'
bundle.fingerprint() == '7b2200ff24230f76cea22e5eb15b1701'

}

Expand Down

0 comments on commit b59fa72

Please sign in to comment.