Revert "llnl.util.filesystem.find: restore old error handling (#47463)"
This reverts commit a31c525778
.
This commit is contained in:
parent
60ba61f6b2
commit
4fbdf2f2c0
@ -1741,11 +1741,6 @@ def find(root, files, recursive=True, max_depth: Optional[int] = None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _log_file_access_issue(e: OSError, path: str) -> None:
|
|
||||||
errno_name = errno.errorcode.get(e.errno, "UNKNOWN")
|
|
||||||
tty.debug(f"find must skip {path}: {errno_name} {e}")
|
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter(arg_slice=slice(1))
|
@system_path_filter(arg_slice=slice(1))
|
||||||
def find_max_depth(root, globs, max_depth: Optional[int] = None):
|
def find_max_depth(root, globs, max_depth: Optional[int] = None):
|
||||||
"""Given a set of non-recursive glob file patterns, finds all
|
"""Given a set of non-recursive glob file patterns, finds all
|
||||||
@ -1759,10 +1754,19 @@ def find_max_depth(root, globs, max_depth: Optional[int] = None):
|
|||||||
If ``globs`` is a list, files matching earlier entries are placed
|
If ``globs`` is a list, files matching earlier entries are placed
|
||||||
in the return value before files matching later entries.
|
in the return value before files matching later entries.
|
||||||
"""
|
"""
|
||||||
|
# If root doesn't exist, then we say we found nothing. If it
|
||||||
|
# exists but is not a dir, we assume the user would want to
|
||||||
|
# know; likewise if it exists but we do not have permission to
|
||||||
|
# access it.
|
||||||
try:
|
try:
|
||||||
stat_root = os.stat(root)
|
stat_root = os.stat(root)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
return []
|
if e.errno == errno.ENOENT:
|
||||||
|
return []
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
if not stat.S_ISDIR(stat_root.st_mode):
|
||||||
|
raise ValueError(f"{root} is not a directory")
|
||||||
|
|
||||||
if max_depth is None:
|
if max_depth is None:
|
||||||
max_depth = sys.maxsize
|
max_depth = sys.maxsize
|
||||||
@ -1786,6 +1790,10 @@ def _dir_id(stat_info):
|
|||||||
# https://github.com/python/cpython/blob/3.9/Python/fileutils.c
|
# https://github.com/python/cpython/blob/3.9/Python/fileutils.c
|
||||||
return (stat_info.st_ino, stat_info.st_dev)
|
return (stat_info.st_ino, stat_info.st_dev)
|
||||||
|
|
||||||
|
def _log_file_access_issue(e):
|
||||||
|
errno_name = errno.errorcode.get(e.errno, "UNKNOWN")
|
||||||
|
tty.debug(f"find must skip {dir_entry.path}: {errno_name} {str(e)}")
|
||||||
|
|
||||||
visited_dirs = set([_dir_id(stat_root)])
|
visited_dirs = set([_dir_id(stat_root)])
|
||||||
|
|
||||||
# Each queue item stores the depth and path
|
# Each queue item stores the depth and path
|
||||||
@ -1800,8 +1808,9 @@ def _dir_id(stat_info):
|
|||||||
depth, next_dir = dir_queue.pop()
|
depth, next_dir = dir_queue.pop()
|
||||||
try:
|
try:
|
||||||
dir_iter = os.scandir(next_dir)
|
dir_iter = os.scandir(next_dir)
|
||||||
except OSError as e:
|
except OSError:
|
||||||
_log_file_access_issue(e, next_dir)
|
# Most commonly, this would be a permissions issue, for
|
||||||
|
# example if we are scanning an external directory like /usr
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with dir_iter:
|
with dir_iter:
|
||||||
@ -1812,7 +1821,7 @@ def _dir_id(stat_info):
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
# Possible permission issue, or a symlink that cannot
|
# Possible permission issue, or a symlink that cannot
|
||||||
# be resolved (ELOOP).
|
# be resolved (ELOOP).
|
||||||
_log_file_access_issue(e, dir_entry.path)
|
_log_file_access_issue(e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if it_is_a_dir and (depth < max_depth):
|
if it_is_a_dir and (depth < max_depth):
|
||||||
@ -1828,7 +1837,7 @@ def _dir_id(stat_info):
|
|||||||
else:
|
else:
|
||||||
stat_info = dir_entry.stat(follow_symlinks=True)
|
stat_info = dir_entry.stat(follow_symlinks=True)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
_log_file_access_issue(e, dir_entry.path)
|
_log_file_access_issue(e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dir_id = _dir_id(stat_info)
|
dir_id = _dir_id(stat_info)
|
||||||
|
Loading…
Reference in New Issue
Block a user