Fetch all remotes and return a boolean to let the calling function know whether or not any remotes were updated in the process of fetching
(self, remotes=None)
| 3430 | return cleared, errors |
| 3431 | |
| 3432 | def fetch_remotes(self, remotes=None): |
| 3433 | """ |
| 3434 | Fetch all remotes and return a boolean to let the calling function know |
| 3435 | whether or not any remotes were updated in the process of fetching |
| 3436 | """ |
| 3437 | if remotes is None: |
| 3438 | remotes = [] |
| 3439 | elif isinstance(remotes, str): |
| 3440 | remotes = remotes.split(",") |
| 3441 | elif not isinstance(remotes, list): |
| 3442 | log.error( |
| 3443 | "Invalid 'remotes' argument (%s) for fetch_remotes. " |
| 3444 | "Must be a list of strings", |
| 3445 | remotes, |
| 3446 | ) |
| 3447 | remotes = [] |
| 3448 | |
| 3449 | changed = False |
| 3450 | for repo in self.remotes: |
| 3451 | name = getattr(repo, "name", None) |
| 3452 | if not remotes or (repo.id, name) in remotes or name in remotes: |
| 3453 | try: |
| 3454 | # Find and place fetch_request file for all the other branches for this repo |
| 3455 | repo_work_hash = os.path.split(repo.get_salt_working_dir())[0] |
| 3456 | branches = [ |
| 3457 | os.path.relpath(path, repo_work_hash) |
| 3458 | for (path, subdirs, files) in os.walk(repo_work_hash) |
| 3459 | if not subdirs |
| 3460 | ] |
| 3461 | |
| 3462 | for branch in branches: |
| 3463 | # Don't place fetch request in current branch being updated |
| 3464 | if branch == repo.get_cache_basename(): |
| 3465 | continue |
| 3466 | branch_salt_dir = salt.utils.path.join(repo_work_hash, branch) |
| 3467 | fetch_path = salt.utils.path.join( |
| 3468 | branch_salt_dir, "fetch_request" |
| 3469 | ) |
| 3470 | if os.path.isdir(branch_salt_dir): |
| 3471 | try: |
| 3472 | with salt.utils.files.fopen(fetch_path, "w"): |
| 3473 | pass |
| 3474 | except OSError as exc: # pylint: disable=broad-except |
| 3475 | log.error( |
| 3476 | "Failed to make fetch request: %s %s", |
| 3477 | fetch_path, |
| 3478 | exc, |
| 3479 | exc_info=True, |
| 3480 | ) |
| 3481 | else: |
| 3482 | log.error("Failed to make fetch request: %s", fetch_path) |
| 3483 | for branch in os.listdir(repo_work_hash): |
| 3484 | # Don't place fetch request in current branch being updated |
| 3485 | if branch == repo.get_cache_basename(): |
| 3486 | continue |
| 3487 | branch_salt_dir = salt.utils.path.join(repo_work_hash, branch) |
| 3488 | fetch_path = salt.utils.path.join( |
| 3489 | branch_salt_dir, "fetch_request" |