Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3006.x]Fix tech-debt for Git Pillar data with os.walk #67723

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/67733.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use os.walk to traverse git branches, and no longer replace slash '/' in git branch names
31 changes: 28 additions & 3 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ def _val_cb(x, y):
self._cache_basename = "_"
if self.id.startswith("__env__"):
try:
self._cache_basename = self.get_checkout_target().replace(
"/", "-"
) # replace '/' with '-' to not cause trouble with file-system
self._cache_basename = self.get_checkout_target()

except AttributeError:
log.critical(
Expand Down Expand Up @@ -2800,6 +2798,33 @@ def fetch_remotes(self, remotes=None):
try:
# Find and place fetch_request file for all the other branches for this repo
repo_work_hash = os.path.split(repo.get_salt_working_dir())[0]
branches = [
os.path.relpath(path, repo_work_hash)
for (path, subdirs, files) in os.walk(repo_work_hash)
if not subdirs
]

for branch in branches:
# Don't place fetch request in current branch being updated
if branch == repo.get_cache_basename():
continue
branch_salt_dir = salt.utils.path.join(repo_work_hash, branch)
fetch_path = salt.utils.path.join(
branch_salt_dir, "fetch_request"
)
if os.path.isdir(branch_salt_dir):
try:
with salt.utils.files.fopen(fetch_path, "w"):
pass
except OSError as exc: # pylint: disable=broad-except
log.error(
"Failed to make fetch request: %s %s",
fetch_path,
exc,
exc_info=True,
)
else:
log.error("Failed to make fetch request: %s", fetch_path)
for branch in os.listdir(repo_work_hash):
# Don't place fetch request in current branch being updated
if branch == repo.get_cache_basename():
Expand Down
Loading