comparison mercurial/cffi/osutil.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 521ac0d7047f
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
38 def __init__(self, st_mode, st_mtime, st_size): 38 def __init__(self, st_mode, st_mtime, st_size):
39 self.st_mode = st_mode 39 self.st_mode = st_mode
40 self.st_mtime = st_mtime 40 self.st_mtime = st_mtime
41 self.st_size = st_size 41 self.st_size = st_size
42 42
43 tv_sec_ofs = ffi.offsetof("struct timespec", "tv_sec") 43 tv_sec_ofs = ffi.offsetof(b"struct timespec", b"tv_sec")
44 buf = ffi.new("char[]", listdir_batch_size) 44 buf = ffi.new(b"char[]", listdir_batch_size)
45 45
46 def listdirinternal(dfd, req, stat, skip): 46 def listdirinternal(dfd, req, stat, skip):
47 ret = [] 47 ret = []
48 while True: 48 while True:
49 r = lib.getattrlistbulk(dfd, req, buf, listdir_batch_size, 0) 49 r = lib.getattrlistbulk(dfd, req, buf, listdir_batch_size, 0)
50 if r == 0: 50 if r == 0:
51 break 51 break
52 if r == -1: 52 if r == -1:
53 raise OSError(ffi.errno, os.strerror(ffi.errno)) 53 raise OSError(ffi.errno, os.strerror(ffi.errno))
54 cur = ffi.cast("val_attrs_t*", buf) 54 cur = ffi.cast(b"val_attrs_t*", buf)
55 for i in range(r): 55 for i in range(r):
56 lgt = cur.length 56 lgt = cur.length
57 assert lgt == ffi.cast('uint32_t*', cur)[0] 57 assert lgt == ffi.cast(b'uint32_t*', cur)[0]
58 ofs = cur.name_info.attr_dataoffset 58 ofs = cur.name_info.attr_dataoffset
59 str_lgt = cur.name_info.attr_length 59 str_lgt = cur.name_info.attr_length
60 base_ofs = ffi.offsetof('val_attrs_t', 'name_info') 60 base_ofs = ffi.offsetof(b'val_attrs_t', b'name_info')
61 name = str( 61 name = str(
62 ffi.buffer( 62 ffi.buffer(
63 ffi.cast("char*", cur) + base_ofs + ofs, str_lgt - 1 63 ffi.cast(b"char*", cur) + base_ofs + ofs, str_lgt - 1
64 ) 64 )
65 ) 65 )
66 tp = attrkinds[cur.obj_type] 66 tp = attrkinds[cur.obj_type]
67 if name == "." or name == "..": 67 if name == b"." or name == b"..":
68 continue 68 continue
69 if skip == name and tp == statmod.S_ISDIR: 69 if skip == name and tp == statmod.S_ISDIR:
70 return [] 70 return []
71 if stat: 71 if stat:
72 mtime = cur.mtime.tv_sec 72 mtime = cur.mtime.tv_sec
83 ) 83 )
84 ) 84 )
85 else: 85 else:
86 ret.append((name, tp)) 86 ret.append((name, tp))
87 cur = ffi.cast( 87 cur = ffi.cast(
88 "val_attrs_t*", int(ffi.cast("intptr_t", cur)) + lgt 88 b"val_attrs_t*", int(ffi.cast(b"intptr_t", cur)) + lgt
89 ) 89 )
90 return ret 90 return ret
91 91
92 def listdir(path, stat=False, skip=None): 92 def listdir(path, stat=False, skip=None):
93 req = ffi.new("struct attrlist*") 93 req = ffi.new(b"struct attrlist*")
94 req.bitmapcount = lib.ATTR_BIT_MAP_COUNT 94 req.bitmapcount = lib.ATTR_BIT_MAP_COUNT
95 req.commonattr = ( 95 req.commonattr = (
96 lib.ATTR_CMN_RETURNED_ATTRS 96 lib.ATTR_CMN_RETURNED_ATTRS
97 | lib.ATTR_CMN_NAME 97 | lib.ATTR_CMN_NAME
98 | lib.ATTR_CMN_OBJTYPE 98 | lib.ATTR_CMN_OBJTYPE