cgilsxml.py: prévoir le cas où le fichier disparait pendant que la liste est construite
This commit is contained in:
parent
2fc7392fe1
commit
c00d9e42ed
|
@ -143,7 +143,7 @@ class File:
|
|||
|
||||
def __init__(self, dir=None, name=None, pf=None, dontlist=False):
|
||||
if pf is None:
|
||||
if dir is None or name is None: raise ValueError("either dir/name or pf must be specified")
|
||||
if dir is None or name is None: raise ValueError("either (dir,name) or pf must be specified")
|
||||
pf = path.join(dir, name)
|
||||
dir, name = path.split(pf) # il est possible que name soit de la forme subdir/name
|
||||
dir = path.abspath(dir)
|
||||
|
@ -186,7 +186,10 @@ def find_files(basedir, filters):
|
|||
if deep_filters:
|
||||
for dirpath, dirnames, filenames in os.walk(basedir):
|
||||
for filename in filenames:
|
||||
file = File(dirpath, filename)
|
||||
# race condition: si le fichier disparait entre-temps, une
|
||||
# exception se produit
|
||||
try: file = File(dirpath, filename)
|
||||
except: continue
|
||||
matched = False
|
||||
allowed = False
|
||||
for filter in deep_filters:
|
||||
|
@ -199,7 +202,10 @@ def find_files(basedir, filters):
|
|||
simple_filters = [filter for filter in filters if filter.re_spec is not None and not filter.deep_scan]
|
||||
if simple_filters:
|
||||
for name in os.listdir(basedir):
|
||||
file = File(basedir, name)
|
||||
# race condition: si le fichier disparait entre-temps, une
|
||||
# exception se produit
|
||||
try: file = File(basedir, name)
|
||||
except: continue
|
||||
if not file.isfile(): continue
|
||||
matched = False
|
||||
allowed = False
|
||||
|
@ -213,10 +219,21 @@ def find_files(basedir, filters):
|
|||
glob_filters = [filter for filter in filters if filter.glob is not None]
|
||||
if glob_filters:
|
||||
for filter in glob_filters:
|
||||
candidates = []
|
||||
if filter.deep_scan:
|
||||
candidates = [File(pf=pf) for pf in glob.glob(path.join(basedir, filter.glob))]
|
||||
for pf in glob.glob(path.join(basedir, filter.glob)):
|
||||
# race condition: si le fichier disparait entre-temps, une
|
||||
# exception se produit
|
||||
try: file = File(pf=pf)
|
||||
except: continue
|
||||
candidates.append(file)
|
||||
else:
|
||||
candidates = [File(basedir, name) for name in os.listdir(basedir)]
|
||||
for name in os.listdir(basedir):
|
||||
# race condition: si le fichier disparait entre-temps, une
|
||||
# exception se produit
|
||||
try: file = File(basedir, name)
|
||||
except: continue
|
||||
candidates.append(file)
|
||||
for file in candidates:
|
||||
if not file.isfile(): continue
|
||||
elif filter.match_fill(file): pass
|
||||
|
|
Loading…
Reference in New Issue