[PATCH 3/3] Default to stdin/stdout in bup meta when -f is not specified.

27 views
Skip to first unread message

Rob Browning

unread,
Oct 17, 2012, 9:48:05 PM10/17/12
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
---
Documentation/bup-meta.md | 2 +-
cmd/meta-cmd.py | 16 +++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/Documentation/bup-meta.md b/Documentation/bup-meta.md
index 853d097..a53cc4c 100644
--- a/Documentation/bup-meta.md
+++ b/Documentation/bup-meta.md
@@ -37,7 +37,7 @@ access permissions, etc.) for a set of filesystem paths.

-t, \--list
: Display information about the metadata in an archive. Read the
- archive from standard output unless `--file` is specified.
+ archive from standard input unless `--file` is specified.

-x, \--extract
: Extract a metadata archive. Conceptually, perform `--start-extract`
diff --git a/cmd/meta-cmd.py b/cmd/meta-cmd.py
index 4d4aac6..b557ba3 100755
--- a/cmd/meta-cmd.py
+++ b/cmd/meta-cmd.py
@@ -15,10 +15,15 @@ from bup.helpers import handle_ctrl_c, log, saved_errors


def open_input(name):
- if name != '-':
- return open(name, 'r')
- else:
+ if not name or name == '-':
return sys.stdin
+ return open(name, 'r')
+
+
+def open_output(name):
+ if not name or name == '-':
+ return sys.stdout
+ return open(name, 'w')


optspec = """
@@ -61,10 +66,7 @@ if action_count == 0:
if opt.create:
if len(remainder) < 1:
o.fatal("no paths specified for create")
- if opt.file != '-':
- output_file = open(opt.file, 'w')
- else:
- output_file = sys.stdout
+ output_file = open_output(opt.file)
metadata.save_tree(output_file,
remainder,
recurse=opt.recurse,
--
1.7.10.4

Rob Browning

unread,
Oct 17, 2012, 9:48:04 PM10/17/12
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
---
lib/bup/metadata.py | 40 ++++++++++++++++++++--------------------
lib/bup/t/tmetadata.py | 4 ++--
2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py
index 3ae4db1..a741278 100644
--- a/lib/bup/metadata.py
+++ b/lib/bup/metadata.py
@@ -159,7 +159,7 @@ def _clean_up_extract_path(p):
# must be unique, and must *never* be changed.
_rec_tag_end = 0
_rec_tag_path = 1
-_rec_tag_common = 2 # times, owner, group, type, perms, etc.
+_rec_tag_common = 2 # times, user, group, type, perms, etc.
_rec_tag_symlink_target = 3
_rec_tag_posix1e_acl = 4 # getfacl(1), setfacl(1), etc.
_rec_tag_nfsv4_acl = 5 # intended to supplant posix1e acls?
@@ -190,9 +190,9 @@ class Metadata:
self.atime = st.st_atime
self.mtime = st.st_mtime
self.ctime = st.st_ctime
- self.owner = self.group = ''
+ self.user = self.group = ''
try:
- self.owner = pwd.getpwuid(st.st_uid)[0]
+ self.user = pwd.getpwuid(st.st_uid)[0]
except KeyError, e:
add_error("no user name for id %s '%s'" % (st.st_gid, path))
try:
@@ -207,7 +207,7 @@ class Metadata:
result = vint.pack('VVsVsVvVvVvV',
self.mode,
self.uid,
- self.owner,
+ self.user,
self.gid,
self.group,
self.rdev,
@@ -223,7 +223,7 @@ class Metadata:
data = vint.read_bvec(port)
(self.mode,
self.uid,
- self.owner,
+ self.user,
self.gid,
self.group,
self.rdev,
@@ -322,25 +322,25 @@ class Metadata:
else:
raise

- # Don't try to restore owner unless we're root, and even
- # if asked, don't try to restore the owner or group if
+ # Don't try to restore user unless we're root, and even
+ # if asked, don't try to restore the user or group if
# it doesn't exist in the system db.
uid = self.uid
gid = self.gid
if not restore_numeric_ids:
- if not self.owner:
+ if not self.user:
uid = -1
- add_error('ignoring missing owner for "%s"\n' % path)
+ add_error('ignoring missing user for "%s"\n' % path)
else:
if not is_superuser():
- uid = -1 # Not root; assume we can't change owner.
+ uid = -1 # Not root; assume we can't change user.
else:
try:
- uid = pwd.getpwnam(self.owner)[2]
+ uid = pwd.getpwnam(self.user)[2]
except KeyError:
uid = -1
- fmt = 'ignoring unknown owner %s for "%s"\n'
- add_error(fmt % (self.owner, path))
+ fmt = 'ignoring unknown user %s for "%s"\n'
+ add_error(fmt % (self.user, path))
if not self.group:
gid = -1
add_error('ignoring missing group for "%s"\n' % path)
@@ -697,7 +697,7 @@ all_fields = frozenset(['path',
'size',
'uid',
'gid',
- 'owner',
+ 'user',
'group',
'atime',
'mtime',
@@ -709,9 +709,9 @@ all_fields = frozenset(['path',

def summary_str(meta):
mode_val = xstat.mode_str(meta.mode)
- owner_val = meta.owner
- if not owner_val:
- owner_val = str(meta.uid)
+ user_val = meta.user
+ if not user_val:
+ user_val = str(meta.uid)
group_val = meta.group
if not group_val:
group_val = str(meta.gid)
@@ -726,7 +726,7 @@ def summary_str(meta):
if stat.S_ISLNK(meta.mode):
path_val += ' -> ' + meta.symlink_target
return '%-10s %-11s %11s %16s %s' % (mode_val,
- owner_val + "/" + group_val,
+ user_val + "/" + group_val,
size_or_dev_val,
time_val,
path_val)
@@ -758,8 +758,8 @@ def detailed_str(meta, fields = None):
result.append('uid: ' + str(meta.uid))
if 'gid' in fields:
result.append('gid: ' + str(meta.gid))
- if 'owner' in fields:
- result.append('owner: ' + meta.owner)
+ if 'user' in fields:
+ result.append('user: ' + meta.user)
if 'group' in fields:
result.append('group: ' + meta.group)
if 'atime' in fields:
diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py
index fc5df0c..89a440f 100644
--- a/lib/bup/t/tmetadata.py
+++ b/lib/bup/t/tmetadata.py
@@ -193,8 +193,8 @@ def test_restore_nonexistent_user_group():
os.mkdir(path)
m = metadata.from_path(path, archive_path=path, save_symlinks=True)
WVPASSEQ(m.path, path)
- junk,m.owner = max([(len(x.pw_name), x.pw_name + 'x')
- for x in pwd.getpwall()])
+ junk,m.user = max([(len(x.pw_name), x.pw_name + 'x')
+ for x in pwd.getpwall()])
junk,m.group = max([(len(x.gr_name), x.gr_name + 'x')
for x in grp.getgrall()])
WVPASSEQ(m.apply_to_path(path, restore_numeric_ids=True), None)
--
1.7.10.4

Zoran Zaric

unread,
Oct 18, 2012, 12:12:47 AM10/18/12
to Rob Browning, bup-...@googlegroups.com
On Wed, Oct 17, 2012 at 08:48:04PM -0500, Rob Browning wrote:
> Signed-off-by: Rob Browning <r...@defaultvalue.org>

Reviewed-by: Zoran Zaric <z...@zoranzaric.de>

Zoran Zaric

unread,
Oct 18, 2012, 12:15:51 AM10/18/12
to Rob Browning, bup-...@googlegroups.com
On Wed, Oct 17, 2012 at 08:48:05PM -0500, Rob Browning wrote:
> Signed-off-by: Rob Browning <r...@defaultvalue.org>

Reviewed-by: Zoran Zaric <z...@zoranzaric.de>

Rob Browning

unread,
Oct 19, 2012, 9:00:47 PM10/19/12
to Zoran Zaric, bup-...@googlegroups.com
Zoran Zaric <z...@zoranzaric.de> writes:

> On Wed, Oct 17, 2012 at 08:48:05PM -0500, Rob Browning wrote:
>> Signed-off-by: Rob Browning <r...@defaultvalue.org>
>
> Reviewed-by: Zoran Zaric <z...@zoranzaric.de>

Thanks -- will be pushed soon.

--
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4

Rob Browning

unread,
Oct 19, 2012, 9:01:27 PM10/19/12
to Zoran Zaric, bup-...@googlegroups.com
Zoran Zaric <z...@zoranzaric.de> writes:

> On Wed, Oct 17, 2012 at 08:48:04PM -0500, Rob Browning wrote:
>> Signed-off-by: Rob Browning <r...@defaultvalue.org>
>
> Reviewed-by: Zoran Zaric <z...@zoranzaric.de>

Reply all
Reply to author
Forward
0 new messages