Fix listDirectory.

develop
Mike Hiretsky 13 years ago
parent ea525ea1f6
commit 12b918b272

@ -767,16 +767,26 @@ def getFilesCount(directory):
os.walk(directory)),[]))
return 0
def listDirectory(directory):
def listDirectory(directory,findCycle=None):
"""Get files from directory, if it exists"""
if os.path.exists(directory) and \
os.access(directory,os.R_OK) and \
(stat.S_ISDIR(os.lstat(directory)[stat.ST_MODE]) or
(stat.S_ISLNK(os.lstat(directory)[stat.ST_MODE]) and
stat.S_ISDIR(os.lstat(os.readlink(directory))[stat.ST_MODE]))):
return os.listdir(directory)
else:
return []
try:
if os.path.exists(directory) and \
os.access(directory,os.R_OK) and \
stat.S_ISDIR(os.lstat(directory)[stat.ST_MODE]):
return os.listdir(directory)
elif stat.S_ISLNK(os.lstat(directory)[stat.ST_MODE]):
realfile = os.path.join(os.path.dirname(directory),
os.readlink(directory))
if not findCycle:
findCycle = [directory]
else:
if realfile in findCycle:
return []
findCycle.append(directory)
return listDirectory(realfile,findCycle)
except OSError:
pass
return []
def detectDeviceForPartition(dev):
"""Detect parent device for partition by /sys/block (sysfs)"""

Loading…
Cancel
Save