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

Use lockfile feature only when not in offline mode #2371

Merged
merged 1 commit into from
Aug 31, 2022
Merged
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
24 changes: 14 additions & 10 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ def initialize_options(arguments: list[str] | None = None) -> None:

# add a lock file so we do not have two instances running inside at the same time
os.makedirs(options.cache_dir, exist_ok=True)
options.cache_dir_lock = FileLock(f"{options.cache_dir}/.lock")
try:
options.cache_dir_lock.acquire(timeout=120)
except Timeout:
_logger.error(
"Timeout waiting for another instance of ansible-lint to release the lock."
)
sys.exit(LOCK_TIMEOUT_RC)

options.cache_dir_lock = None
if not options.offline:
options.cache_dir_lock = FileLock(f"{options.cache_dir}/.lock")
try:
options.cache_dir_lock.acquire(timeout=120)
except Timeout:
_logger.error(
"Timeout waiting for another instance of ansible-lint to release the lock."
)
sys.exit(LOCK_TIMEOUT_RC)


def _do_list(rules: RulesCollection) -> int:
Expand Down Expand Up @@ -248,8 +251,9 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901
app.render_matches(result.matches)

_perform_mockings_cleanup()
options.cache_dir_lock.release()
pathlib.Path(options.cache_dir_lock.lock_file).unlink(missing_ok=True)
if options.cache_dir_lock:
options.cache_dir_lock.release()
pathlib.Path(options.cache_dir_lock.lock_file).unlink(missing_ok=True)

return app.report_outcome(result, mark_as_success=mark_as_success)

Expand Down