Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dot and empty paths normalized correctly for COPY to WORKDIR #5080

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

profnandaa
Copy link
Collaborator

@profnandaa profnandaa commented Jun 24, 2024

In my previous fix on #4825, I had removed this line knowing that all that had been addressed in pahtRelativeToWorkingDir:

	if cfg.params.DestPath == "." // <-- this one
		|| cfg.params.DestPath == ""
                || cfg.params.DestPath[len(cfg.params.DestPath)-1] == filepath.Separator {
		dest += string(filepath.Separator)
	}

However, I had overlooked the "." and "" scenarios. "". The "/"case is handled correctly in system.NormalizePath().

This change therefore undoes this, to make sure "." is transformed correctly to "./" during COPY operation, same to "" -> "./". This is important especially for WORKDIR that are not /, so that COPY --link operations are handled properly.

fixes #5070

@profnandaa profnandaa requested a review from tonistiigi June 24, 2024 15:50
@profnandaa profnandaa force-pushed the fix-dot-path-5070 branch 2 times, most recently from 5cd38aa to ce59dbf Compare June 24, 2024 15:57
@profnandaa
Copy link
Collaborator Author

profnandaa commented Jun 24, 2024

While we're here, I was torn between adding this case to NormalizePath or reverting to how it was initially at func dispatchCopy.
Also wanted to understand the intention for this block: @gabriel-samfira

} else if strings.HasSuffix(origPath, "/.") {
if newPath != "/" {
newPath += "/"
}
newPath += "."
}

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need regression integration test for this as well. Is this something that should be handled by pathRelativeToWorkingDir (that part could be follow up).

@tonistiigi tonistiigi added this to the v0.14.2 milestone Jun 24, 2024
@profnandaa profnandaa force-pushed the fix-dot-path-5070 branch 4 times, most recently from 45d8652 to 4abc6ad Compare June 26, 2024 13:13
@@ -1763,9 +1763,6 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform)
return "", err
}

if len(p) == 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: removed so that empty directory "" are handled properly, especially for non-root WORKDIR. That's where the regression happens.

@profnandaa
Copy link
Collaborator Author

We need regression integration test for this as well. Is this something that should be handled by pathRelativeToWorkingDir (that part could be follow up).

Sure, it's better at pathRelativeToWorkingDir, I've moved it and also fixed how "" dir's were being handled.

Added the integration tests. It was very interesting that the tests were passing even without the fix, if you have / as the WORKDIR; and was getting a little thrown off. However, fixed with: WORKDIR /var/www and could repro the regression correctly.

@profnandaa profnandaa changed the title fix: dot path normalized correctly for COPY fix: dot path normalized correctly for COPY to WORKDIR Jun 26, 2024
@profnandaa profnandaa changed the title fix: dot path normalized correctly for COPY to WORKDIR fix: dot and empty paths normalized correctly for COPY to WORKDIR Jun 26, 2024
In my previous fix on moby#4825, I had removed this line
knowing that all that had been addressed in `pahtRelativeToWorkingDir`:

```go
	if cfg.params.DestPath == "." // <-- this one
		|| cfg.params.DestPath == "" ||
		cfg.params.DestPath[len(cfg.params.DestPath)-1] == filepath.Separator {
		dest += string(filepath.Separator)
	}
```

However, I had overlooked the `"."` and `""` scenarios. `""`.
The  `"/"`case is handled correctly in `system.NormalizePath()`.

This change therefore undoes this, to make sure "." is transformed
correctly to "./" during COPY operation, same to "" -> "./". This
is important especially for WORKDIR that are not `/`, so that
`COPY --link` operations are handled properly.

fixes moby#5070

Signed-off-by: Anthony Nandaa <[email protected]>
@profnandaa
Copy link
Collaborator Author

@tonistiigi - PTAL again.

@tonistiigi tonistiigi merged commit 835e9fd into moby:master Jun 28, 2024
75 checks passed
@profnandaa profnandaa deleted the fix-dot-path-5070 branch June 29, 2024 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v0.14] dockerfile: mkdir xxxx not a directory - with COPY --link
2 participants