-def write_file_content(fullname, n):
- outf = open(fullname, 'wb')
- try:
- for b in chunkyreader(n.open()):
- outf.write(b)
- finally:
- outf.close()
-
-
-def write_file_content_sparsely(fullname, n):
- outfd = os.open(fullname, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
- try:
- trailing_zeros = 0;
- for b in chunkyreader(n.open()):
- trailing_zeros = write_sparsely(outfd, b, 512, trailing_zeros)
- pos = os.lseek(outfd, trailing_zeros, os.SEEK_END)
- os.ftruncate(outfd, pos)
- finally:
- os.close(outfd)
-
-
-def find_dir_item_metadata_by_name(dir, name):
- """Find metadata in dir (a node) for an item with the given name,
- or for the directory itself if the name is ''."""
- meta_stream = None
- try:
- mfile = dir.metadata_file() # VFS file -- cannot close().
- if mfile:
- meta_stream = mfile.open()
- # First entry is for the dir itself.
- meta = metadata.Metadata.read(meta_stream)
- if name == '':
- return meta
- for sub in dir:
- if stat.S_ISDIR(sub.mode):
- meta = find_dir_item_metadata_by_name(sub, '')
- else:
- meta = metadata.Metadata.read(meta_stream)
- if sub.name == name:
- return meta
- finally:
- if meta_stream:
- meta_stream.close()
-
-
-def do_root(n, sparse, owner_map, restore_root_meta = True):
- # Very similar to do_node(), except that this function doesn't
- # create a path for n's destination directory (and so ignores
- # n.fullname). It assumes the destination is '.', and restores
- # n's metadata and content there.
- global total_restored, opt
- meta_stream = None
- try:
- # Directory metadata is the first entry in any .bupm file in
- # the directory. Get it.
- mfile = n.metadata_file() # VFS file -- cannot close().
- root_meta = None
- if mfile:
- meta_stream = mfile.open()
- root_meta = metadata.Metadata.read(meta_stream)
- print_info(n, '.')
- total_restored += 1
- plog('Restoring: %d\r' % total_restored)
- for sub in n:
- m = None
- # Don't get metadata if this is a dir -- handled in sub do_node().
- if meta_stream and not stat.S_ISDIR(sub.mode):
- m = metadata.Metadata.read(meta_stream)
- do_node(n, sub, sparse, owner_map, meta = m)
- if root_meta and restore_root_meta:
- apply_metadata(root_meta, '.', opt.numeric_ids, owner_map)
- finally:
- if meta_stream:
- meta_stream.close()
+ if not treeish:
+ # Do this now so we'll have meta.symlink_target for verbose output
+ item = vfs.augment_item_meta(repo, item, include_size=True)
+ meta = item.meta
+ assert(meta.mode == mode)
+
+ if stat.S_ISDIR(mode):
+ if verbosity >= 1:
+ print('%s/' % fullname)
+ elif stat.S_ISLNK(mode):
+ assert(meta.symlink_target)
+ if verbosity >= 2:
+ print('%s@ -> %s' % (fullname, meta.symlink_target))
+ else:
+ if verbosity >= 2:
+ print(fullname)