|
4 | 4 | Used by buildnml. See buildnml for documetation.
|
5 | 5 | """
|
6 | 6 |
|
7 |
| -import os, sys, re |
| 7 | +import os, sys, re, pwd, grp, stat, getpass |
8 | 8 | from collections import OrderedDict
|
9 | 9 |
|
10 | 10 | import xml.etree.ElementTree as ET
|
@@ -953,7 +953,37 @@ def create_input_data_list_file(case,caseroot):
|
953 | 953 | # Only add files whose full path starts with the CIME's input data location
|
954 | 954 | if file_path.startswith(din_loc_root):
|
955 | 955 | fd.write("scream_dl_input_{} = {}\n".format(idx, file_path))
|
956 |
| - |
| 956 | + if os.path.exists(file_path): |
| 957 | + if os.path.isdir(file_path): |
| 958 | + raise IsADirectoryError(f"Input file '{file_path}' is a directory, not a regular file.") |
| 959 | + if not os.path.isfile(file_path): |
| 960 | + raise OSError(f"Input file '{file_path}' exists but is not a regular file.") |
| 961 | + if not os.access(file_path,os.R_OK): |
| 962 | + try: |
| 963 | + file_stat = os.stat(file_path) |
| 964 | + |
| 965 | + # Get owner and group names |
| 966 | + owner = pwd.getpwuid(file_stat.st_uid).pw_name |
| 967 | + group = grp.getgrgid(file_stat.st_gid).gr_name |
| 968 | + |
| 969 | + # Get file permissions |
| 970 | + permissions = stat.filemode(file_stat.st_mode) |
| 971 | + |
| 972 | + except Exception as e: |
| 973 | + raise RuntimeError(f"Error retrieving file info for '{file_path}': {e}") |
| 974 | + |
| 975 | + curr_user = getpass.getuser() |
| 976 | + user_info = pwd.getpwnam(curr_user) |
| 977 | + group_ids = os.getgrouplist(curr_user, user_info.pw_gid) |
| 978 | + curr_groups = [grp.getgrgid(gid).gr_name for gid in group_ids] |
| 979 | + |
| 980 | + raise PermissionError ("Input file exists but it is not readable for current user\n" |
| 981 | + f" - file name: {file_path}\n" |
| 982 | + f" - file owner: {owner}\n" |
| 983 | + f" - file group: {group}\n" |
| 984 | + f" - permissions: {permissions}\n" |
| 985 | + f" - current user: {curr_user}\n" |
| 986 | + f" - current user groups: {curr_groups}") |
957 | 987 |
|
958 | 988 | ###############################################################################
|
959 | 989 | def do_cime_vars_on_yaml_output_files(case, caseroot):
|
|
0 commit comments