Skip to content

scripts: isolate directory navigation using subshells to fix path state corruption - #965

Open
darkKnight386 wants to merge 1 commit into
CachyOS:masterfrom
darkKnight386:master
Open

scripts: isolate directory navigation using subshells to fix path state corruption#965
darkKnight386 wants to merge 1 commit into
CachyOS:masterfrom
darkKnight386:master

Conversation

@darkKnight386

Copy link
Copy Markdown

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.

…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.
@CherrieTheShifter

Copy link
Copy Markdown

Yes This

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants