Skip to content

Commit 57ff414

Browse files
Merge pull request #150 from matyasselmeci/wip/fixcerttest
Catch OSError in core.check_file_and_perms()
2 parents c125c3d + 17950d6 commit 57ff414

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

osgtest/library/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,19 @@ def check_file_ownership(file_path, owner_name):
647647
file_stat = os.stat(file_path)
648648
return (file_stat.st_uid == owner_uid.pw_uid and
649649
stat.S_ISREG(file_stat.st_mode))
650-
except OSError: # file does not exist
650+
except OSError: # file does not exist
651651
return False
652652

653653
def check_file_and_perms(file_path, owner_name, permissions):
654654
"""Return True if the file at 'file_path' exists, is owned by
655655
'owner_name', is a file, and has the given permissions; False otherwise
656656
"""
657-
file_stat = os.stat(file_path)
658-
return (check_file_ownership(file_path, owner_name) and
659-
file_stat.st_mode & 0o7777 == permissions)
657+
try:
658+
file_stat = os.stat(file_path)
659+
return (check_file_ownership(file_path, owner_name) and
660+
file_stat.st_mode & 0o7777 == permissions)
661+
except OSError: # file does not exist
662+
return False
660663

661664
def parse_env_output(output):
662665
"""

0 commit comments

Comments
 (0)