The fix for #984 addressed a problem when /run/user/0 already exists and
ccache is run with fakeroot. However, it didn’t handle the case when
/run/user/0/ccache-tmp already exists, which will happen for instance if
the real root user has run ccache at least once.
Fix this by using access(2) to verify that the ccache-tmp directory is
writable. Note: Can’t just check the mode bits of the directory since
they appear OK since fakeroot fakes the UID.
Fixes #1044.
static const std::string run_user_tmp_dir = [] {
#ifdef HAVE_GETEUID
auto dir = FMT("/run/user/{}/ccache-tmp", geteuid());
- if (Util::create_dir(dir)) {
+ if (Util::create_dir(dir) && access(dir.c_str(), W_OK) == 0) {
return dir;
}
#endif