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

build_log: make sure to carry the old uid and gid #1362

Closed
wants to merge 4 commits into from

Conversation

marcelhollerbach
Copy link

see #1302 as a normal workflow you do things like "ninja all && sudo
ninja install" for the case that the install target executes a build
target then ninja_log will be writte ntwo which will result in its
permissions to be root / root, which is a problem since you cannot
execute the workflow from above again.

src/build_log.cc Outdated Show resolved Hide resolved
see ninja-build#1302 as a normal workflow you do things like "ninja all && sudo
ninja install" for the case that the install target executes a build
target then ninja_log will be writte ntwo which will result in its
permissions to be root / root, which is a problem since you cannot
execute the workflow from above again.
this file does the same, and should also maintain the permissions
@marcelhollerbach
Copy link
Author

Okay its resolved, i saw that the problem is also in deps_log, so i added the same there!

@ilyapopov
Copy link

How portable is this? (What about Windows?)

it is now a function called ReplaceContent, since it will replace the
content of a file, while carrying the ownership of the file.
@marcelhollerbach
Copy link
Author

I have 2 patches that are making them portable, i just can compile them, but cannot run them (dont have a windows maschine arround ... ) I hope i can get tomorrow a running windows maschine and run it on there ...

this will just delete the path to replace.

The ownership issue like we have it on windows is way
@marcelhollerbach
Copy link
Author

I made it now work on windows (took a while to dive into theire api). Works now on windows and linux!

Any other comments? Or can it proceed ?

@Stefan-Schmidt
Copy link

Is there anything blocking this PR to get accepted?
We have seen this issue several times in the process of getting our project moved from autotools+make to meson+ninja

Copy link
Collaborator

@nico nico left a comment

Choose a reason for hiding this comment

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

Looks conceptually good to me.

}
}
#else
if (!CopyFile(old_path.c_str(), path.c_str(), false))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the same behavior as the unlink/rename you're replacing, right? can we just keep using unlink/replace then?

And then that part could be shared still and it'd look like

#if !defined(_WIN32)
stat()
#endif
unlink()
rename()
#if !defined(_WIN32)
chown()
#endfi

Copy link
Author

Choose a reason for hiding this comment

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

Well, as far as I remember CopyFile keeps the owner of the new file as long as it exists. And only copies the content, i cannot find any source anymore saying that. However, when doing only unlink() rename() the same issue we have on linux hits on windows ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, thanks. Sounds subtle. I could imagine someone coming along and "simplifying" this code to what I just proposed some time later. I wonder if there's something we could do to stop them since using CopyFile() is important here. Do you think it's possible to write an automated test for that? Maybe create a file with non-standard permissions, call CopyFile() and check the new file has the non-standard permissions? Ideally in a way that the test fails if someone does the change I proposed here.

found_uid_gid = false;
}

if (unlink(path.c_str()) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Per #1572, this should probably ignore ENOENT errors.

@marcelhollerbach
Copy link
Author

This is replaced with #1588, i cannot update this one here anymore

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

5 participants