@@ -634,19 +634,25 @@ def get_hostname():
634
634
except socket .error :
635
635
return None
636
636
637
+ def check_file_ownership (file_path , owner_name ):
638
+ """Return True if at 'file_path' exists, is owned by
639
+ 'owner_name' and is a is a file
640
+ """
641
+ owner_uid = pwd .getpwnam (owner_name )
642
+ try :
643
+ file_stat = os .stat (file_path )
644
+ return (file_stat .st_uid == owner_uid and
645
+ stat .S_ISREG (file_stat .st_mode ))
646
+ except OSError : # file does not exist
647
+ return False
637
648
638
649
def check_file_and_perms (file_path , owner_name , permissions ):
639
- """Return True if the file at 'file_path' exists, is owned by
640
- 'owner_name', is a file, and has the given permissions; False otherwise
641
- """
642
- owner_uid = pwd .getpwnam (owner_name )
643
- try :
644
- file_stat = os .stat (file_path )
645
- return (file_stat .st_uid == owner_uid and
646
- file_stat .st_mode & 0o7777 == permissions and
647
- stat .S_ISREG (file_stat .st_mode ))
648
- except OSError : # file does not exist
649
- return False
650
+ """Return True if the file at 'file_path' exists, is owned by
651
+ 'owner_name', is a file, and has the given permissions; False otherwise
652
+ """
653
+ file_stat = os .stat (file_path )
654
+ return check_file_ownership (file_path , owner_name ) and
655
+ file_stat .st_mode & 0o7777 == permissions
650
656
651
657
def parse_env_output (output ):
652
658
"""
0 commit comments