+ 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_str(meta, numeric_ids = False, classification = None,
+ human_readable = False):
+
+ """Return a string 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)
+ symlink_target = meta.symlink_target
+ mtime_secs = xstat.fstime_floor_secs(meta.mtime)
+ mtime_str = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
+ if meta.user and not numeric_ids:
+ user_str = meta.user
+ elif meta.uid != None:
+ user_str = str(meta.uid)
+ if meta.group and not numeric_ids:
+ group_str = meta.group
+ elif meta.gid != None:
+ group_str = str(meta.gid)
+ 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))
+ elif meta.size != None:
+ if human_readable:
+ size_or_dev_str = format_filesize(meta.size)
+ else:
+ size_or_dev_str = str(meta.size)
+ else:
+ size_or_dev_str = '-'
+ if classification:
+ classification_str = \
+ xstat.classification_str(meta.mode, classification == 'all')
+ else:
+ mode_str = '?' * 10
+ mtime_str = '????-??-?? ??:??'
+ classification_str = '?'
+
+ name = name or ''
+ if classification:
+ name += classification_str
+ if symlink_target:
+ name += ' -> ' + meta.symlink_target
+
+ return '%-10s %-11s %11s %16s %s' % (mode_str,
+ user_str + "/" + group_str,
+ size_or_dev_str,
+ mtime_str,
+ name)
+
+
+def detailed_str(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 ''
+ result.append('path: ' + path)
+ if 'mode' in fields:
+ result.append('mode: %s (%s)' % (oct(meta.mode),
+ xstat.mode_str(meta.mode)))
+ if 'link-target' in fields and stat.S_ISLNK(meta.mode):
+ result.append('link-target: ' + meta.symlink_target)
+ if 'rdev' in fields:
+ if meta.rdev:
+ result.append('rdev: %d,%d' % (os.major(meta.rdev),
+ os.minor(meta.rdev)))
+ else:
+ result.append('rdev: 0')
+ if 'size' in fields and meta.size:
+ result.append('size: ' + str(meta.size))
+ if 'uid' in fields:
+ result.append('uid: ' + str(meta.uid))
+ if 'gid' in fields:
+ result.append('gid: ' + str(meta.gid))
+ if 'user' in fields:
+ result.append('user: ' + meta.user)
+ if 'group' in fields:
+ result.append('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('atime: ' + xstat.fstime_to_sec_str(meta.atime))
+ else:
+ result.append('atime: 0')
+ if 'mtime' in fields:
+ if xstat.lutime or not stat.S_ISLNK(meta.mode):
+ result.append('mtime: ' + xstat.fstime_to_sec_str(meta.mtime))
+ else:
+ result.append('mtime: 0')
+ if 'ctime' in fields:
+ result.append('ctime: ' + xstat.fstime_to_sec_str(meta.ctime))
+ if 'linux-attr' in fields and meta.linux_attr:
+ result.append('linux-attr: ' + hex(meta.linux_attr))
+ if 'linux-xattr' in fields and meta.linux_xattr:
+ for name, value in meta.linux_xattr:
+ result.append('linux-xattr: %s -> %s' % (name, repr(value)))
+ if 'posix1e-acl' in fields and meta.posix1e_acl:
+ acl = meta.posix1e_acl[0]
+ result.append('posix1e-acl: ' + acl + '\n')
+ if stat.S_ISDIR(meta.mode):
+ def_acl = meta.posix1e_acl[2]
+ result.append('posix1e-acl-default: ' + def_acl + '\n')
+ return '\n'.join(result)