-
Notifications
You must be signed in to change notification settings - Fork 14
Add a file hashing utility to the Utilities class. #234
Conversation
This makes cache key generation no longer sensitive to file ordering, but adds sensitivity to file naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! One comment asking for an additional test.
def hashFiles(filesToHash: Seq[File], rootDir: File): String = { | ||
// Resolve the filenames relative to the root directory. | ||
val rootDirPath = rootDir.toPath | ||
val relativizedNames = filesToHash.map(_.toPath).map(rootDirPath.relativize).map(_.toString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume relativize will create a canonical path? If I feed it "foo/dir/../dir" what happens? Probably add a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, yes.
Test added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you were asking another thing! I'll check that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah-ha! It does not. Good catch; I'll add a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another test added. :)
I'll merge on green, unless I hear otherwise!
Actually, there is no semaphore integration here, so I will just merge one I run the tests again locally! |
tempDirectory.getName + File.pathSeparatorChar + "bar.txt") | ||
|
||
val firstHash = Utilities.hashFiles(Seq(fooFile, barFile), tempDirectory) | ||
val secondHash = Utilities.hashFiles(Seq(fooFile, barFile), tempDirectory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the second hash attempt use a different (denormalized) path to barFile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! Indeed. I'll send a follow-up.
* Add a file hashing utility to the Utilities class. This makes cache key generation no longer sensitive to file ordering, but adds sensitivity to file naming. * Create a unit test exercising path relativization. * Add logic to normalize paths before hashing, and a test exercising this.
This makes cache key generation no longer sensitive to file ordering, but adds sensitivity to file naming.
One more utility method for generating file hashes. This will be used a few times in the Docker image generation code.