Skip to content

Commit

Permalink
check command state before accessing return value (#4700)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak authored Jan 2, 2025
1 parent a71ea61 commit 975ea6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tools/src/main/python/opengrok_tools/scm/cvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

#
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright (c) 2020, Krystof Tulinger <k.tulinger@seznam.cz>
#

Expand All @@ -44,7 +44,7 @@ def reposync(self):
cmd.execute()
self.logger.info("output of {}:".format(cmd))
self.logger.info(cmd.getoutputstr())
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
self.logger.error("failed to perform update: command {}"
"in directory {} exited with {}".
format(hg_command, self.path, cmd.getretcode()))
Expand Down
4 changes: 2 additions & 2 deletions tools/src/main/python/opengrok_tools/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

#
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright (c) 2020, Krystof Tulinger <k.tulinger@seznam.cz>
#

Expand All @@ -44,7 +44,7 @@ def _configure_git_pull(self):
cmd = self.get_command(git_command, work_dir=self.path,
env_vars=self.env, logger=self.logger)
cmd.execute()
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
cmd.log_error("failed to configure git pull.ff")

def reposync(self):
Expand Down
8 changes: 4 additions & 4 deletions tools/src/main/python/opengrok_tools/scm/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_branch(self):
cmd.execute()
self.logger.info("output of {}:".format(cmd))
self.logger.info(cmd.getoutputstr())
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
cmd.log_error("failed to get branch")
return None
else:
Expand Down Expand Up @@ -73,7 +73,7 @@ def reposync(self):
cmd.execute()
self.logger.info("output of {}:".format(cmd))
self.logger.info(cmd.getoutputstr())
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
cmd.log_error("failed to perform pull")
return 1

Expand All @@ -98,7 +98,7 @@ def reposync(self):
cmd.execute()
self.logger.info("output of {}:".format(cmd))
self.logger.info(cmd.getoutputstr())
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
cmd.log_error("failed to perform pull and update")
return 1

Expand Down Expand Up @@ -157,7 +157,7 @@ def strip_outgoing(self):
# If the 'hg out' command fails for some reason, it will return 255.
# Hence, check for positive value as bail out indication.
#
if status > 0:
if cmd.getstate() != Command.FINISHED or status > 0:
return False

revisions = list(filter(None, cmd.getoutputstr().split("\n")))
Expand Down
4 changes: 2 additions & 2 deletions tools/src/main/python/opengrok_tools/scm/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

#
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
# Portions Copyright (c) 2020, Krystof Tulinger <k.tulinger@seznam.cz>
#

Expand Down Expand Up @@ -161,7 +161,7 @@ def _run_command(self, command):
cmd = self.get_command(command, work_dir=self.path,
env_vars=self.env, logger=self.logger)
cmd.execute()
if cmd.getretcode() != 0 or cmd.getstate() != Command.FINISHED:
if cmd.getstate() != Command.FINISHED or cmd.getretcode() != 0:
cmd.log_error("failed to perform command {}".format(command))
status = cmd.getretcode()
if status == 0 and cmd.getstate() != Command.FINISHED:
Expand Down

0 comments on commit 975ea6f

Please sign in to comment.