Use access() to check if the root directory is writable.

This is more reliable than testing if the user is root as in some
chroot environments root directory may be writable by a non-root user.
This commit is contained in:
Andrey Semashev 2022-12-15 15:53:42 +03:00
parent 141727b568
commit d204b41dba

View File

@ -1232,7 +1232,7 @@ void create_directories_tests()
BOOST_TEST(!ec); BOOST_TEST(!ec);
#ifdef BOOST_POSIX_API #ifdef BOOST_POSIX_API
if (geteuid() > 0) if (access("/", W_OK) != 0)
{ {
ec.clear(); ec.clear();
BOOST_TEST(!fs::create_directories("/foo", ec)); // may be OK on Windows BOOST_TEST(!fs::create_directories("/foo", ec)); // may be OK on Windows