+ meta.create_path(meta.path, create_symlinks=create_symlinks)
+
+
+all_fields = frozenset(['path',
+ 'mode',
+ 'link-target',
+ 'rdev',
+ 'size',
+ 'uid',
+ 'gid',
+ 'user',
+ 'group',
+ 'atime',
+ 'mtime',
+ 'ctime',
+ 'linux-attr',
+ 'linux-xattr',
+ 'posix1e-acl'])
+
+
+def summary_bytes(meta, numeric_ids = False, classification = None,
+ human_readable = False):
+ """Return bytes containing the "ls -l" style listing for meta.
+ Classification may be "all", "type", or None."""
+ user_str = group_str = size_or_dev_str = '?'
+ symlink_target = None
+ if meta:
+ name = meta.path
+ mode_str = xstat.mode_str(meta.mode).encode('ascii')
+ symlink_target = meta.symlink_target
+ mtime_secs = xstat.fstime_floor_secs(meta.mtime)
+ mtime_str = strftime('%Y-%m-%d %H:%M',
+ time.localtime(mtime_secs)).encode('ascii')
+ if meta.user and not numeric_ids:
+ user_str = meta.user
+ elif meta.uid != None:
+ user_str = str(meta.uid).encode()
+ if meta.group and not numeric_ids:
+ group_str = meta.group
+ elif meta.gid != None:
+ group_str = str(meta.gid).encode()
+ if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
+ if meta.rdev:
+ size_or_dev_str = ('%d,%d' % (os.major(meta.rdev),
+ os.minor(meta.rdev))).encode()
+ elif meta.size != None:
+ if human_readable:
+ size_or_dev_str = format_filesize(meta.size).encode()
+ else:
+ size_or_dev_str = str(meta.size).encode()
+ else:
+ size_or_dev_str = b'-'
+ if classification:
+ classification_str = \
+ xstat.classification_str(meta.mode,
+ classification == 'all').encode()
+ else:
+ mode_str = b'?' * 10
+ mtime_str = b'????-??-?? ??:??'
+ classification_str = b'?'
+
+ name = name or b''
+ if classification:
+ name += classification_str
+ if symlink_target:
+ name += b' -> ' + meta.symlink_target
+
+ return b'%-10s %-11s %11s %16s %s' % (mode_str,
+ user_str + b'/' + group_str,
+ size_or_dev_str,
+ mtime_str,
+ name)
+
+
+def detailed_bytes(meta, fields = None):
+ # FIXME: should optional fields be omitted, or empty i.e. "rdev:
+ # 0", "link-target:", etc.
+ if not fields:
+ fields = all_fields
+
+ result = []
+ if 'path' in fields:
+ path = meta.path or b''
+ result.append(b'path: ' + path)
+ if 'mode' in fields:
+ result.append(b'mode: %o (%s)'
+ % (meta.mode, xstat.mode_str(meta.mode).encode('ascii')))
+ if 'link-target' in fields and stat.S_ISLNK(meta.mode):
+ result.append(b'link-target: ' + meta.symlink_target)
+ if 'rdev' in fields:
+ if meta.rdev:
+ result.append(b'rdev: %d,%d' % (os.major(meta.rdev),
+ os.minor(meta.rdev)))
+ else:
+ result.append(b'rdev: 0')
+ if 'size' in fields and meta.size is not None:
+ result.append(b'size: %d' % meta.size)
+ if 'uid' in fields:
+ result.append(b'uid: %d' % meta.uid)
+ if 'gid' in fields:
+ result.append(b'gid: %d' % meta.gid)
+ if 'user' in fields:
+ result.append(b'user: ' + meta.user)
+ if 'group' in fields:
+ result.append(b'group: ' + meta.group)
+ if 'atime' in fields:
+ # If we don't have xstat.lutime, that means we have to use
+ # utime(), and utime() has no way to set the mtime/atime of a
+ # symlink. Thus, the mtime/atime of a symlink is meaningless,
+ # so let's not report it. (That way scripts comparing
+ # before/after won't trigger.)
+ if xstat.lutime or not stat.S_ISLNK(meta.mode):
+ result.append(b'atime: ' + xstat.fstime_to_sec_bytes(meta.atime))
+ else:
+ result.append(b'atime: 0')
+ if 'mtime' in fields:
+ if xstat.lutime or not stat.S_ISLNK(meta.mode):
+ result.append(b'mtime: ' + xstat.fstime_to_sec_bytes(meta.mtime))
+ else:
+ result.append(b'mtime: 0')
+ if 'ctime' in fields:
+ result.append(b'ctime: ' + xstat.fstime_to_sec_bytes(meta.ctime))
+ if 'linux-attr' in fields and meta.linux_attr:
+ result.append(b'linux-attr: %x' % meta.linux_attr)
+ if 'linux-xattr' in fields and meta.linux_xattr:
+ for name, value in meta.linux_xattr:
+ result.append(b'linux-xattr: %s -> %s' % (name, value))
+ if 'posix1e-acl' in fields and meta.posix1e_acl:
+ acl = meta.posix1e_acl[0]
+ result.append(b'posix1e-acl: ' + acl + b'\n')
+ if stat.S_ISDIR(meta.mode):
+ def_acl = meta.posix1e_acl[2]
+ result.append(b'posix1e-acl-default: ' + def_acl + b'\n')
+ return b'\n'.join(result)