Skip to content

Commit

Permalink
lib: mkdir_parents() - Avoid unnecessary syscalls when uid/gid doesn'…
Browse files Browse the repository at this point in the history
…t change

There's no need to open() + fchown() the directory after mkdir(), if neither
uid nor gid changes.
  • Loading branch information
sirainen authored and cmouse committed Nov 26, 2024
1 parent 1d6f95c commit e3bbaad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/mkdir-parents.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ mkdir_chown_full(const char *path, mode_t mode, uid_t uid,
umask(old_mask);
if (ret < 0)
break;
if (uid == (uid_t)-1 && gid == (gid_t)-1) {
/* no changes to owner/group */
return 0;
}

fd = open(path, O_RDONLY);
if (fd != -1)
break;
Expand Down

0 comments on commit e3bbaad

Please sign in to comment.