diff -r bdd257d60da2 Lib/mhlib.py --- a/Lib/mhlib.py Tue Nov 10 19:53:37 2015 +0200 +++ b/Lib/mhlib.py Wed Nov 11 09:48:17 2015 +0200 @@ -110,6 +110,7 @@ class MH: path = os.path.expanduser(path) if not os.path.isdir(path): raise Error, 'MH() path not found' self.path = path + self._use_nlinks = os.stat(path).st_nlink >= 2 def __repr__(self): """String representation.""" @@ -156,11 +157,12 @@ class MH: """Return the names of the subfolders in a given folder (prefixed with the given folder name).""" fullname = os.path.join(self.path, name) - # Get the link count so we can avoid listing folders - # that have no subfolders. - nlinks = os.stat(fullname).st_nlink - if nlinks <= 2: - return [] + if self._use_nlinks: + # Get the link count so we can avoid listing folders + # that have no subfolders. + nlinks = os.stat(fullname).st_nlink + if nlinks <= 2: + return [] subfolders = [] subnames = os.listdir(fullname) for subname in subnames: @@ -168,11 +170,12 @@ class MH: if os.path.isdir(fullsubname): name_subname = os.path.join(name, subname) subfolders.append(name_subname) - # Stop looking for subfolders when - # we've seen them all - nlinks = nlinks - 1 - if nlinks <= 2: - break + if self._use_nlinks: + # Stop looking for subfolders when + # we've seen them all + nlinks = nlinks - 1 + if nlinks <= 2: + break subfolders.sort() return subfolders @@ -183,11 +186,12 @@ class MH: def listallsubfolders(self, name): """Return the names of subfolders in a given folder, recursively.""" fullname = os.path.join(self.path, name) - # Get the link count so we can avoid listing folders - # that have no subfolders. - nlinks = os.stat(fullname).st_nlink - if nlinks <= 2: - return [] + if self._use_nlinks: + # Get the link count so we can avoid listing folders + # that have no subfolders. + nlinks = os.stat(fullname).st_nlink + if nlinks <= 2: + return [] subfolders = [] subnames = os.listdir(fullname) for subname in subnames: @@ -200,11 +204,12 @@ class MH: subsubfolders = self.listallsubfolders( name_subname) subfolders = subfolders + subsubfolders - # Stop looking for subfolders when - # we've seen them all - nlinks = nlinks - 1 - if nlinks <= 2: - break + if self._use_nlinks: + # Stop looking for subfolders when + # we've seen them all + nlinks = nlinks - 1 + if nlinks <= 2: + break subfolders.sort() return subfolders