commit: 11bbb434ce4d71a29ceaa912dbdb68470bd9302f Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Wed Jun 18 04:43:30 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed Jun 18 09:51:59 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=11bbb434
emerge-webrsync: don't check for directory existence independently of mkdir -p If only mkdir(1) had an option that would instruct it not to propagate EEXIST errors. That way, one would be able to avoid an independent test for the existence of the directory that amounts to a minor TOCTOU. One might name the option -p, perhaps. What say you, dear reader? Link: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> Signed-off-by: Sam James <sam <AT> gentoo.org> bin/emerge-webrsync | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync index f6a1a0de24..b6b278bff9 100755 --- a/bin/emerge-webrsync +++ b/bin/emerge-webrsync @@ -46,19 +46,16 @@ main() { handle_pgp_setup - if [[ ! -d ${repo_location} ]]; then - mkdir -p "${repo_location}" || exit - - if contains_word usersync "${FEATURES}"; then - chown "${PORTAGE_USERNAME}":"${PORTAGE_GRPNAME}" "${repo_location}" || exit - fi + mkdir -p "${repo_location}" || exit + if contains_word usersync "${FEATURES}"; then + chown "${PORTAGE_USERNAME}":"${PORTAGE_GRPNAME}" "${repo_location}" || exit fi if [[ ! -w ${repo_location} ]] ; then die "Repository '${repo_name}' is not writable: ${repo_location}" fi - [[ -d ${PORTAGE_TMPDIR}/portage ]] || mkdir -p "${PORTAGE_TMPDIR}/portage" + mkdir -p "${PORTAGE_TMPDIR}/portage" # Create a temporary directory whose subsequent removal is guaranteed. tmpdir= @@ -68,7 +65,7 @@ main() { || exit (( opt[keep] )) || DISTDIR=${tmpdir} - [[ ! -d "${DISTDIR}" ]] && mkdir -p "${DISTDIR}" + mkdir -p "${DISTDIR}" if (( opt[keep] )) && [[ ! -w ${DISTDIR} ]] ; then die "DISTDIR is not writable: ${DISTDIR}"
