Skip to content

fix(init): make home preparation complete and retryable #448

Description

@ss-o

Problem

.zi-prepare-home marks initialization complete before its directory work succeeds, and creates ZI[SERVICES_DIR] only when ZI[SNIPPETS_DIR] is absent.

Current source:

  • zi/zi.zsh

    Lines 1172 to 1236 in 7956627

    .zi-prepare-home() {
    [[ -n ${ZI[HOME_READY]} ]] && return
    ZI[HOME_READY]=1
    if [[ ! -d ${ZI[HOME_DIR]} ]]; then
    command mkdir -p "${ZI[HOME_DIR]}"
    command chmod 700 "${ZI[HOME_DIR]}"
    fi
    # Set up $ZPFX
    if [[ ! -d ${ZPFX}/bin ]]; then
    command mkdir -p "${ZPFX}/bin"
    fi
    if [[ ! -d ${ZPFX}/lib ]]; then
    command mkdir -p "${ZPFX}/lib"
    command chmod go-w "${ZPFX}/lib"
    fi
    if [[ ! -d ${ZPFX}/share ]]; then
    command mkdir -p "${ZPFX}/share"
    command chmod go-w "${ZPFX}/share"
    fi
    if [[ ! -d ${ZI[MAN_DIR]} ]]; then
    command mkdir 2>/dev/null -p ${~ZI[MAN_DIR]}/man{1..9}
    command chmod -R go-w "${ZI[MAN_DIR]}"
    fi
    if [[ ! -d ${ZI[CACHE_DIR]} ]]; then
    command mkdir -p "${ZI[CACHE_DIR]}"
    command chmod 700 "${ZI[CACHE_DIR]}"
    fi
    if [[ ! -d ${ZI[CONFIG_DIR]} ]]; then
    command mkdir -p "${ZI[CONFIG_DIR]}"
    command chmod 700 "${ZI[CONFIG_DIR]}"
    fi
    if [[ ! -d ${ZI[LOG_DIR]} ]]; then
    command mkdir -p "${ZI[LOG_DIR]}"
    command chmod 700 "${ZI[LOG_DIR]}"
    fi
    if [[ ! -d ${ZI[ZMODULES_DIR]} ]]; then
    command mkdir -p "${ZI[ZMODULES_DIR]}"
    command chmod go-w "${ZI[ZMODULES_DIR]}"
    fi
    if [[ ! -d ${ZI[PLUGINS_DIR]}/_local---zi ]]; then
    command rm -rf "${ZI[PLUGINS_DIR]:-${TMPDIR:-/tmp}/132bcaCAB}/_local---zi"
    command mkdir -p "${ZI[PLUGINS_DIR]}/_local---zi"
    command chmod go-w "${ZI[PLUGINS_DIR]}"
    command ln -s "${ZI[BIN_DIR]}/lib/_zi" "${ZI[PLUGINS_DIR]}/_local---zi"
    (( ${+functions[.zi-setup-plugin-dir]} )) || builtin source "${ZI[BIN_DIR]}/lib/zsh/install.zsh" || return 1
    (( ${+functions[.zi-confirm]} )) || builtin source "${ZI[BIN_DIR]}/lib/zsh/autoload.zsh" || return 1
    .zi-clear-completions &>/dev/null
    .zi-compinit 1 &>/dev/null
    fi
    if [[ ! -d ${ZI[COMPLETIONS_DIR]} ]]; then
    command mkdir "${ZI[COMPLETIONS_DIR]}"
    command chmod go-w "${ZI[COMPLETIONS_DIR]}"
    # Symlink _zi completion into _local---zi directory.
    command ln -s "${ZI[PLUGINS_DIR]}/_local---zi/_zi" "${ZI[COMPLETIONS_DIR]}"
    (( ${+functions[.zi-setup-plugin-dir]} )) || builtin source "${ZI[BIN_DIR]}/lib/zsh/install.zsh" || return 1
    .zi-compinit 1 &>/dev/null
    fi
    if [[ ! -d ${ZI[SNIPPETS_DIR]} ]]; then
    command mkdir -p "${ZI[SNIPPETS_DIR]}/OMZ::plugins"
    command chmod go-w "${ZI[SNIPPETS_DIR]}"
    ( builtin cd -q ${ZI[SNIPPETS_DIR]}; command ln -s OMZ::plugins plugins; )
    command mkdir -p "${ZI[SERVICES_DIR]}"
    command chmod go-w "${ZI[SERVICES_DIR]}"
    fi
    } # ]]]

Reproduction evidence

With an isolated Zi root where snippets/ already existed and services/ did not, sourcing Zi completed but the service directory remained absent:

service_dir_rc=1

Several directory commands also do not propagate failure, while ZI[HOME_READY]=1 prevents a later retry.

Impact

Partial, migrated, or manually repaired layouts can be accepted as ready. Service startup then tries to create locks and FIFOs below a missing directory, and transient initialization failures can persist for the shell session.

Acceptance criteria

  • Establish and validate each required directory independently.
  • Propagate creation, permission, link, and initialization failures.
  • Set ZI[HOME_READY] only after successful completion.
  • Leave retry possible after a failed preparation.
  • Add tests for partial layouts, existing paths, permission failure, and retry.

Next action

Define the complete home-layout invariant, then make preparation transactional at the function level.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ziZi core behavior, APIs, or documentation.type:bugSomething is broken or behaving incorrectly.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions