core-util: Make pa_make_secure_dir() act like mkdir -p

This makes pa_make_secure_dir() create any missing parent directories in
the given path as well. This is useful, for example, on a pristine
system with a clean $HOME that needs ~/.config/pulse/ to be created when
~/.config does not exist.
This commit is contained in:
Arun Raghavan 2012-06-11 13:12:50 +05:30
parent b942af65fe
commit 59968f8e2c

View file

@ -220,9 +220,11 @@ void pa_make_fd_cloexec(int fd) {
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
struct stat st;
int r, saved_errno;
pa_bool_t retry = TRUE;
pa_assert(dir);
again:
#ifdef OS_IS_WIN32
r = mkdir(dir);
#else
@ -234,6 +236,14 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
}
#endif
if (r < 0 && errno == ENOENT && retry) {
/* If a parent directory in the path doesn't exist, try to create that
* first, then try again. */
pa_make_secure_parent_dir(dir, m, uid, gid);
retry = FALSE;
goto again;
}
if (r < 0 && errno != EEXIST)
return -1;