diff options
Diffstat (limited to 'tests/utils/gfid-access.py')
-rwxr-xr-x | tests/utils/gfid-access.py | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/tests/utils/gfid-access.py b/tests/utils/gfid-access.py index 556d2b4c65b..c35c1223df6 100755 --- a/tests/utils/gfid-access.py +++ b/tests/utils/gfid-access.py @@ -33,23 +33,51 @@ def _fmt_mkdir(l): def _fmt_symlink(l1, l2): return "!II%dsI%ds%ds" % (37, l1+1, l2+1) -def entry_pack_reg(gf, bn, mo, uid, gid): - blen = len(bn) - return struct.pack(_fmt_mknod(blen), - uid, gid, gf, mo, bn, - stat.S_IMODE(mo), 0, umask()) - -def entry_pack_dir(gf, bn, mo, uid, gid): - blen = len(bn) - return struct.pack(_fmt_mkdir(blen), - uid, gid, gf, mo, bn, - stat.S_IMODE(mo), umask()) - -def entry_pack_symlink(gf, bn, lnk, mo, uid, gid): - blen = len(bn) - llen = len(lnk) - return struct.pack(_fmt_symlink(blen, llen), - uid, gid, gf, mo, bn, lnk) + +if sys.version_info > (3,): + def entry_pack_reg(gf, bn, mo, uid, gid): + bn_encoded = bn.encode() + blen = len(bn_encoded) + return struct.pack(_fmt_mknod(blen), + uid, gid, gf.encode(), mo, bn_encoded, + stat.S_IMODE(mo), 0, umask()) + + # mkdir + def entry_pack_dir(gf, bn, mo, uid, gid): + bn_encoded = bn.encode() + blen = len(bn_encoded) + return struct.pack(_fmt_mkdir(blen), + uid, gid, gf.encode(), mo, bn_encoded, + stat.S_IMODE(mo), umask()) + # symlink + def entry_pack_symlink(gf, bn, lnk, st): + bn_encoded = bn.encode() + blen = len(bn_encoded) + lnk_encoded = lnk.encode() + llen = len(lnk_encoded) + return struct.pack(_fmt_symlink(blen, llen), + st['uid'], st['gid'], + gf.encode(), st['mode'], bn_encoded, + lnk_encoded) + +else: + def entry_pack_reg(gf, bn, mo, uid, gid): + blen = len(bn) + return struct.pack(_fmt_mknod(blen), + uid, gid, gf, mo, bn, + stat.S_IMODE(mo), 0, umask()) + + def entry_pack_dir(gf, bn, mo, uid, gid): + blen = len(bn) + return struct.pack(_fmt_mkdir(blen), + uid, gid, gf, mo, bn, + stat.S_IMODE(mo), umask()) + + def entry_pack_symlink(gf, bn, lnk, mo, uid, gid): + blen = len(bn) + llen = len(lnk) + return struct.pack(_fmt_symlink(blen, llen), + uid, gid, gf, mo, bn, lnk) if __name__ == '__main__': if len(sys.argv) < 9: |