mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-12 13:30:10 -05:00
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:
parent
b942af65fe
commit
59968f8e2c
1 changed files with 10 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue