3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
17 # Copyright (C) 2010 Rob Browning
19 # This code is covered under the terms of the GNU Library General
20 # Public License as described in the bup LICENSE file.
22 # TODO: Add tar-like -C option.
24 from __future__ import absolute_import
27 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
29 from bup import compat, metadata
30 from bup import options
31 from bup.compat import argv_bytes
32 from bup.io import byte_stream
33 from bup.helpers import handle_ctrl_c, log, saved_errors
37 if not name or name == b'-':
38 return byte_stream(sys.stdin)
39 return open(name, 'rb')
42 def open_output(name):
43 if not name or name == b'-':
45 return byte_stream(sys.stdout)
46 return open(name, 'wb')
50 bup meta --create [OPTION ...] <PATH ...>
51 bup meta --list [OPTION ...]
52 bup meta --extract [OPTION ...]
53 bup meta --start-extract [OPTION ...]
54 bup meta --finish-extract [OPTION ...]
55 bup meta --edit [OPTION ...] <PATH ...>
57 c,create write metadata for PATHs to stdout (or --file)
58 t,list display metadata
59 x,extract perform --start-extract followed by --finish-extract
60 start-extract build tree matching metadata provided on standard input (or --file)
61 finish-extract finish applying standard input (or --file) metadata to filesystem
62 edit alter metadata; write to stdout (or --file)
63 f,file= specify source or destination file
64 R,recurse recurse into subdirectories
65 xdev,one-file-system don't cross filesystem boundaries
66 numeric-ids apply numeric IDs (user, group, etc.) rather than names
67 symlinks handle symbolic links (default is true)
68 paths include paths in metadata (default is true)
69 set-uid= set metadata uid (via --edit)
70 set-gid= set metadata gid (via --edit)
71 set-user= set metadata user (via --edit)
72 unset-user remove metadata user (via --edit)
73 set-group= set metadata group (via --edit)
74 unset-group remove metadata group (via --edit)
75 v,verbose increase log output (can be used more than once)
76 q,quiet don't show progress meter
81 o = options.Options(optspec)
82 (opt, flags, remainder) = o.parse(['--paths', '--symlinks', '--recurse']
85 opt.verbose = opt.verbose or 0
86 opt.quiet = opt.quiet or 0
87 metadata.verbose = opt.verbose - opt.quiet
88 opt.file = argv_bytes(opt.file) if opt.file else None
90 action_count = sum([bool(x) for x in [opt.create, opt.list, opt.extract,
91 opt.start_extract, opt.finish_extract,
94 o.fatal("bup: only one action permitted: --create --list --extract --edit")
96 o.fatal("bup: no action specified")
99 if len(remainder) < 1:
100 o.fatal("no paths specified for create")
101 output_file = open_output(opt.file)
102 metadata.save_tree(output_file,
103 [argv_bytes(r) for r in remainder],
105 write_paths=opt.paths,
106 save_symlinks=opt.symlinks,
109 if len(remainder) > 0:
110 o.fatal("cannot specify paths for --list")
111 src = open_input(opt.file)
112 metadata.display_archive(src, open_output(b'-'))
113 elif opt.start_extract:
114 if len(remainder) > 0:
115 o.fatal("cannot specify paths for --start-extract")
116 src = open_input(opt.file)
117 metadata.start_extract(src, create_symlinks=opt.symlinks)
118 elif opt.finish_extract:
119 if len(remainder) > 0:
120 o.fatal("cannot specify paths for --finish-extract")
121 src = open_input(opt.file)
122 metadata.finish_extract(src, restore_numeric_ids=opt.numeric_ids)
124 if len(remainder) > 0:
125 o.fatal("cannot specify paths for --extract")
126 src = open_input(opt.file)
127 metadata.extract(src,
128 restore_numeric_ids=opt.numeric_ids,
129 create_symlinks=opt.symlinks)
131 if len(remainder) < 1:
132 o.fatal("no paths specified for edit")
133 output_file = open_output(opt.file)
135 unset_user = False # True if --unset-user was the last relevant option.
136 unset_group = False # True if --unset-group was the last relevant option.
138 if flag[0] == '--set-user':
140 elif flag[0] == '--unset-user':
142 elif flag[0] == '--set-group':
144 elif flag[0] == '--unset-group':
147 for path in remainder:
148 f = open(argv_bytes(path), 'rb')
150 for m in metadata._ArchiveIterator(f):
151 if opt.set_uid is not None:
153 m.uid = int(opt.set_uid)
155 o.fatal("uid must be an integer")
157 if opt.set_gid is not None:
159 m.gid = int(opt.set_gid)
161 o.fatal("gid must be an integer")
165 elif opt.set_user is not None:
166 m.user = argv_bytes(opt.set_user)
170 elif opt.set_group is not None:
171 m.group = argv_bytes(opt.set_group)
179 log('WARNING: %d errors encountered.\n' % len(saved_errors))