add equals/hashCode and toString to MountableFile#2144
Conversation
…`resourcePath` field
| * An abstraction over files and classpath resources aimed at encapsulating all the complexity of generating | ||
| * a path that the Docker daemon is about to create a volume mount for. | ||
| */ | ||
| @EqualsAndHashCode(of = {"path", "forcedFileMode"}) |
There was a problem hiding this comment.
| @EqualsAndHashCode(of = {"path", "forcedFileMode"}) | |
| @EqualsAndHashCode(of = "path") |
There was a problem hiding this comment.
Yes, but wouldn't that be confusing. They are different, after all, if their file mode is different. Otherwise, only the path should be the key.
There was a problem hiding this comment.
They are different, after all, if their file mode is different
they represent the same path. The forced file mode is only a hint that is used to override the one from the file system (but the target object is the same)
There was a problem hiding this comment.
I don't agree, but it's more your code than mine ;-)
|
A lot of checks fail, but they don't seem to be related to my change. |
|
It looks like we've got a real test failure: @Test
public void shouldUseCopyOnlyWithReadOnlyClasspathResources() {
String resource = "/test_copy_to_container.txt";
GenericContainer<?> container = new GenericContainer<>()
.withClasspathResourceMapping(resource, "/readOnly", BindMode.READ_ONLY)
.withClasspathResourceMapping(resource, "/readOnlyNoSelinux", BindMode.READ_ONLY)
.withClasspathResourceMapping(resource, "/readOnlyShared", BindMode.READ_ONLY, SelinuxContext.SHARED)
.withClasspathResourceMapping(resource, "/readWrite", BindMode.READ_WRITE);
Map<MountableFile, String> copyMap = container.getCopyToFileContainerPathMap();
FAILS-->assertTrue("uses copy for read-only", copyMap.containsValue("/readOnly"));
assertTrue("uses copy for read-only and no Selinux", copyMap.containsValue("/readOnlyNoSelinux"));
assertFalse("uses mount for read-only with Selinux", copyMap.containsValue("/readOnlyShared"));
assertFalse("uses mount for read-write", copyMap.containsValue("/readWrite"));
}The This doesn't seem right - it should be valid for one file to be copied to many places, so the original code seems to be wrong. It really feels like |
|
@rnorth: ... or it could be a Actually also the file mode should probably be part of the target, as the same file can end up at multiple locations with different modes, but I guess that would mean a breaking API change. |
|
Perhaps we don’t actually need the container to be a map at all..? For our own usage we only care about iterating over the mount points, so this really just needs to be a list internally. De-duplication is not something we have to do; indeed currently we’ll just be letting Docker figure it out. We don’t have a To avoid this being a breaking change we could keep the signature of |
|
@t1 are you interested in continuing with this PR? |
|
@rnorth : time is — as always — scarce... and this ticket has exploded. It's grown from implementing equals/hasCode to a redesign (even when it's just a small one). I don't think that I'll be able to squeeze out more time for this. My pain with the issue is just too small. It was more of a remove-some-cruft-issue to me. Maybe it would be better to merge what we have than to wait for the full change? |
|
@t1 sorry, but I think I'll close: as it is, there's a real test failure, so we can't merge it. Similarly we're also very time constrained, so I too think that the effort of addressing the comments is not really worth it for a theoretical issue. Thanks for your attempt to improve things, though. |
MountableFileis used as a key in aHashMapbut it doesn't overrideequals/hashcode.I didn't experience any problems, but it definitely has potential for screwing up.
And because the change was so trivial, I also added a
toString.