Add preliminary hardlink support for review.

Thanks to Tim Riemenschneider <git@tim-riemenschneider.de> for
pointing out a compatibility problem (with older versions of Python)
in an earlier version of this patch.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Defer errors when the restore target doesn't support relevant metadata.

When the restore target doesn't support POSIX1e ACLs, extended
attributes, or Linux attributes, handle the failures via add_error()
(i.e. defer them).

Test these cases by creating a loopback VFAT filesystem
(testfs-limited) and using it as a restore target.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Quote EXIT cleanup trap properly in test-meta.sh.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Handle the possibility of a sgid/suid parent dir in one of the meta tests.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Update README regarding metadata support.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Add a metadata() method to Node, File, Symlink, and Dir VFS objects.

The current implementation just populates the self._metadata field of
all of the objects in a directory (and of directory itself) from the
relevant .bupm file whenever metadata() is called on any one of those
objects.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Move tree comparison to t/compare-trees; compare content by default.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Add support for "bup index --exclude-rx <pattern> ...".

When --exclude-rx <pattern> is provided to bup index, exclude any path
matching <pattern>, which must be a Python regular expression
(http://docs.python.org/library/re.html).  The pattern will be
compared against the full path, without anchoring, so "x/y" will match
"ox/yard" or "box/yards".  To exclude the contents of /tmp, but not
the directory itself, use "^/tmp/.".

You may check the behavior at runtime by setting BUP_DEBUG=2 in the
environment.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Add support for "bup restore --exclude-rx <pattern> ...".

When --exclude-rx <pattern> is provided to bup restore, don't restore
any path matching <pattern>, which must be a Python regular expression
(http://docs.python.org/library/re.html).  The pattern will be
compared against the full path, without anchoring, so "x/y" will match
"ox/yard" or "box/yards".  To exclude the contents of /tmp, but not
the directory itself, use "^/tmp/.".

You may check the behavior at runtime by setting BUP_DEBUG=2 in the
environment.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Disallow empty graft points.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Overhaul restore destination handling, and stripping/grafting behavior.

Change restore to respond to source paths like this (assume outdir
corresponds to "." if there no -C argument or to -C outdir):

  /foo/what/ever - extract ever to outdir/ever
  /foo/what/ever/ - extract ever/* to outdir/*
  /foo/what/ever/. - extract ever/. to outdir/. (i.e. outdir == ever).

Also fix handling of top-level commit symlinks.  Previously bup would
just restore /foo/latest as a dummy symlink like this:

   latest -> ../.commit/SHA

Instead, dereference latest and restore the target instead.

Tighten up stripping/grafting with additional argument checks, and
handle any root collisions by creating a fake root dir (see comments
in save-cmd.py).  Bup still doesn't handle other path collisions yet,
i.e. if both /foo/bar and /bar are remapped to /bar.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Redirect t/compare-trees usage to stderr on error.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Don't pass -AX to rsync in t/compare-trees if xattrs aren't supported.

The -AX options won't be available if rsync doesn't report the xattr
capability, so test for that before trying to use them.

Thanks to Yung-Chin Oei <yungchin@yungchin.nl> for the suggested
approach and initial report.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Use python, not groups to grab a user group in t/test-meta.sh.

Group names may actually contain spaces, and since the groups commmand
only reports a space-delimited list of groups on stdout, we had
a problem.

Thanks to "Oei, Yung-Chin" <yungchin@yungchin.nl> and Gabriel Filion
<lelutin@gmail.com> for tracking this down.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Don't pass --tmpdir to mktemp or expect it to have a default template.

BSD mktemp does not understand --tmpdir, and does not have a default
pattern if none is supplied.

Signed-off-by: Yung-Chin Oei <yungchin@yungchin.nl>
Acked-by: Gabriel Filion <lelutin@gmail.com>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
t/test.sh: fix test failure when $top_dir has a dot-name

Fix the admittedly rare case where we're running tests from a tree
that has a dot-name at its base, which only 'bup ls -a' will print.
This problem was originally encountered on a system that keeps mounts
under '/.autofs/'.

Signed-off-by: Yung-Chin Oei <yungchin@yungchin.nl>
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Cache all password (pwd) and group (grp) database lookups.

Thanks to Jann Horn <jannhorn@googlemail.com> for determining that
even just caching user names and group names could provide a notable
performance improvement in some cases.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Handle nonexistent groups in Metadata._apply_common_rec().

Thanks to Oei, Yung-Chin <yungchin@yungchin.nl> for tracking this
down.

Reported-by: Yung-Chin <yungchin@yungchin.nl>
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Change index; include atime; pack time as xstat timespec; use ns in memory.

Update the index format header to 'BUPI\0\0\0\4' (version 4).

Change the index to include atimes, and write all times to bupindex as
xstat timespecs.  This is in preparation for indexing all metadata.
After moving all of the times to the index, there should be far fewer
unique instances of the remaining metadata in many/most cases.

Change the index and index-related code to handle all time
values as integer nanoseconds since the epoch, excepting the packed
format, which (as mentioned above) is now an xstat timespec.

After these changes the index-related in-memory and on-disk time value
handling should match that of the metadata code (i.e. metadata.py,
.bupm, etc.).

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Remove tmax; should be unnecessary with high resolution timestamps.

This effectively reverses 7956f4eb2646d6ff9d56e62ef9e09e8d4763bb46.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>