scripts: isolate directory navigation using subshells to fix path state corruption - #965
Open
darkKnight386 wants to merge 1 commit into
Open
scripts: isolate directory navigation using subshells to fix path state corruption#965darkKnight386 wants to merge 1 commit into
darkKnight386 wants to merge 1 commit into
Conversation
…te corruption Problem: In script.sh, script-znver4.sh, script-v3-v4.sh, and srcinfo.sh, directory navigation inside PKGBUILD processing loops relies on `cd $d` followed by `cd ..`. This pattern suffers from critical flaws: 1. It assumes $d is always exactly one directory level below the root. If find returns nested directory paths (e.g., ./dir1/dir2/PKGBUILD), `cd ..` steps back only one level instead of returning to the repository root. 2. If `cd $d` fails for any reason (e.g., unquoted variables or missing permissions), `cd ..` executes from the wrong working directory, causing all subsequent loop iterations to run in invalid paths and corrupting the build process. Solution: Wrap each package build and metadata generation step inside a subshell block `( cd "$d" || exit 1; ... )`. Because working directory modifications inside subshell processes do not persist after subshell termination: - The main shell context remains securely in the repository root directory at all times. - Eliminates the need for manual `cd ..` calls. - Properly quotes path variables `"$d"` to safely handle paths containing spaces.
|
Yes This |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
In
script.sh,script-znver4.sh,script-v3-v4.sh, andsrcinfo.sh, directory navigation inside PKGBUILD processing loops relies oncd $dfollowed bycd ... This pattern suffers from critical flaws:$dis always exactly one directory level below the root. Iffindreturns nested directory paths (e.g.,./dir1/dir2/PKGBUILD),cd ..steps back only one level instead of returning to the repository root.cd $dfails for any reason (e.g., unquoted variables or missing permissions),cd ..executes from the wrong working directory, causing all subsequent loop iterations to run in invalid paths and corrupting the build process.Solution:
Wrap each package build and metadata generation step inside a subshell block
( cd "$d" || exit 1; ... ). Because working directory modifications inside subshell processes do not persist after subshell termination:cd ..calls."$d"to safely handle paths containing spaces.