comparison mercurial/store.py @ 17747:aad3bce98f76

store: invoke "osutil.listdir()" via vfs This patch invokes "osutil.listdir()" via vfs object. The function added newly to "abstractvfs" is named not as "listdir()" but as "readdir()", because: - "os.listdir()" seems to be more familiar as "listdir()" than "osutil.listdir()" - "osutil.listdir()" returns also type of each files like "readdir()" POSIX API: even though "d_type" field of "dirent" structure is defined mainly only on BSD/Linux This patch invokes "osutil.listdir()" via "rawvfs" object to avoid filename encoding, because the path passed to "osutil.listdir()" shouldn't be encoded. This patch also omits importing "osutil" module, because it is no longer used.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 09 Oct 2012 16:17:55 +0900
parents b9a56b816ff2
children 8095306c1fb2
comparison
equal deleted inserted replaced
17746:6d218e47cf9b 17747:aad3bce98f76
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 import osutil, scmutil, util, parsers 9 import scmutil, util, parsers
10 import os, stat, errno 10 import os, stat, errno
11 11
12 _sha = util.sha1 12 _sha = util.sha1
13 13
14 # This avoids a collision between a file named foo and a dir named 14 # This avoids a collision between a file named foo and a dir named
309 path += '/' + relpath 309 path += '/' + relpath
310 striplen = len(self.path) + 1 310 striplen = len(self.path) + 1
311 l = [] 311 l = []
312 if self.rawvfs.isdir(path): 312 if self.rawvfs.isdir(path):
313 visit = [path] 313 visit = [path]
314 readdir = self.rawvfs.readdir
314 while visit: 315 while visit:
315 p = visit.pop() 316 p = visit.pop()
316 for f, kind, st in osutil.listdir(p, stat=True): 317 for f, kind, st in readdir(p, stat=True):
317 fp = p + '/' + f 318 fp = p + '/' + f
318 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'): 319 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
319 n = util.pconvert(fp[striplen:]) 320 n = util.pconvert(fp[striplen:])
320 l.append((decodedir(n), n, st.st_size)) 321 l.append((decodedir(n), n, st.st_size))
321 elif kind == stat.S_IFDIR and recurse: 322 elif kind == stat.S_IFDIR and recurse: