3 # Return a sorted list of the files in a directory, using a cache
4 # to avoid reading the directory more often than necessary.
5 # Also contains a subroutine to append slashes to directories.
11 def listdir(path
): # List directory contents, using cache
13 cached_mtime
, list = cache
[path
]
16 cached_mtime
, list = -1, []
18 mtime
= os
.stat(path
)[8]
21 if mtime
<> cached_mtime
:
23 list = os
.listdir(path
)
27 cache
[path
] = mtime
, list
30 opendir
= listdir
# XXX backward compatibility
32 def annotate(head
, list): # Add '/' suffixes to directories
33 for i
in range(len(list)):
34 if os
.path
.isdir(os
.path
.join(head
, list[i
])):
35 list[i
] = list[i
] + '/'