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 creation of output directories ending with .. #41

Merged
merged 1 commit into from
Mar 17, 2020

Conversation

sdclarke
Copy link
Contributor

@sdclarke sdclarke commented Mar 6, 2020

After #35 paths containing .. are now handled as defined by the REAPI spec, however a corner case has come up where a directory ending in .. would end up being created and uploaded incorrectly due to the fact the determining the parent directory was done with a call to path.Dir. Extra logic has been added to deal with these cases in this pull request.

Given that this is related to the changes made in #35 I have added testing for this behaviour to the test written in that pull request.

@@ -241,7 +241,12 @@ func (be *localBuildExecutor) Execute(ctx context.Context, filePool re_filesyste
// there. We later use the directory handles to extract output files.
outputParentDirectories := map[string]filesystem.Directory{}
for _, outputDirectory := range command.OutputDirectories {
dirPath := path.Dir(outputDirectory)
var dirPath string
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this part into a helper function?

@@ -583,15 +583,23 @@ func TestLocalBuildExecutorWithWorkingDirectorySuccess(t *testing.T) {
// Creation of build/objects
rootDirectory := mock.NewMockDirectory(ctrl)
rootDirectory.EXPECT().Mkdir("build", os.FileMode(0777)).Return(nil)
rootDirectory.EXPECT().Mkdir("build", os.FileMode(0777)).Return(nil)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this in the second case return syscall.EEXIST?

buildDirectory := mock.NewMockDirectory(ctrl)
rootDirectory.EXPECT().Enter("build").Return(buildDirectory, nil)
rootDirectory.EXPECT().Enter("build").Return(buildDirectory, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Could you please keep this ordered a bit closer to what happens in practice? Also: maybe it's a bit more accurate to use two separate mocks for buildDirectory instead of one. In practice, it won't really happen that Enter() returns the same handle for both Enter() calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of making this test a bit more realistic I'll probably move away from needing to call Enter("build") twice so that should handle this issue.

Copy link
Member

@EdSchouten EdSchouten left a comment

Choose a reason for hiding this comment

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

Sorry for letting you wait. I had to give this some more thought.

We already have that workaround in place to create output directories up front, even though REv2 says we should not. Considering that output_directories is deprecated in favour of output_paths according to the latest version of the protocol, let's just assume that we'll never converge to the originally intended semantics anyway.

What are your thoughts on simply removing support for omitting output directories or letting them be symlinks? That would allow us to make a change like this to fix this specific bug:

https://github.com/buildbarn/bb-remote-execution/compare/issue-41

Note that I have only compile tested this change. The unit tests no longer pass. Could you give this a spin, and if it works integrate it into your branch? Thanks!

This is done by removing the code which creates the parent of the output
directory and simply creating the directory itself directly as it was
being created after the fact anyway
@sdclarke
Copy link
Contributor Author

Note that I have only compile tested this change. The unit tests no longer pass. Could you give this a spin, and if it works integrate it into your branch? Thanks!

I've integrated this and it still seems to work, I also fixed the failing unit tests.

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.

None yet

2 participants