Previously, the time generation code would inexplicably drop parts of
the nanotime -- potentially causing validation to succeed when it should
fail. This was probably do to a bug in the remainder logic, but instead
we should be using .Nanosecond() anyway.
After changing the time of a file with a test case like this:
// Change the time to something known with nanosec != 0.
chtime := time.Unix(100, 987654321)
if err := os.Chtimes("somefile", chtime, chtime); err != nil {
// panic
}
timeKeywordFunc() would return the wrong value (time=100.000000021).
This fixes the issue and adds a test case.
Signed-off-by: Aleksa Sarai <asarai@suse.de>
BSD file's support "flags". These have some similarity with xattr, but
for specific features, rather than general purpose key/values.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
right now, Check() doesn't check for missing/extra files. So, for the
sake of this test, we don't want to do this check for extra/missing files
when we validate the validation manifest produced from a tar against
the "." root directory (which would be /testdata).
Signed-off-by: Stephen Chung <schung@redhat.com>
Default behavior (according to upstream mtree) for validating symlinks
is to just validate the link itself, not to follow it.
Signed-off-by: Stephen Chung <schung@redhat.com>
Instead of checking each time during keyword evaluation if
the keyword is "time", just remove it from the start and
replace it with "tar_time" (if necessary).
Signed-off-by: Stephen Chung <schung@redhat.com>
Resolves#56. Now, the Entry tree will be populated
under a common root (if necessary), so that a manifest can
be accurately generate from a tar file that has been
created using multiple directories.
Signed-off-by: Stephen Chung <schung@redhat.com>
To increase a user's control on how they validate a directory or
tar archive with a specification, it is helpful to know which
keywords are actually used in the spec provided. This way, the user
can see what keywords to use or not use with the '-k' or '-K' flags.
Signed-off-by: Stephen Chung <schung@redhat.com>
Previously, the symlink size reported by a archive/tar header
was 0. This is incorrect, as the size of a symlink should be
the size of its contents, which is just the path to where
the symlink points to. Thus, the size of this file would just
be len(Linkname).
Signed-off-by: Stephen Chung <schung@redhat.com>
Flattening within the readHeaders() function call was problematic
because readHeaders() is called as a goroutine; thus, as the
main program was calling `tdh.writeTo(os.Stdout)`, readHeaders() was
still in the process of flattening the tree structure. To get around this,
we now call flatten in ts.Hierarchy(), such that only when the main program
is ready to retrieve a "valid" DirectoryHierarchy from the archive, should
we flatten the tree.
Signed-off-by: Stephen Chung <schung@redhat.com>
Cleaned up some dead code, and made populateTree not
take in a *tar.Streamer argument, as the ts argument was
only used to set an error. The function now returns
an error (if any). Also made flatten not have to take in
a *tar.Streamer argument as well.
Signed-off-by: Stephen Chung <schung@redhat.com>
Rather than an arbitrary election of hashing the xattr value with SHA1
to avoid leaking the value. By going with base64 encoding it allows for
the possibility of restoring a directory with the values stored in the
manifest.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
Currently, if you create a manifest with, say 'sha1', and another
manifest with 'sha1digest', gomtree will produce different output
with regard to the keyword name. I.e, `sha1=[...]` vs. `sha1digest=[...]`.
If we want to use synonyms for keywords, as well as align with upstream mtree
output, specifying 'sha1' and 'sha1digest' should impact gomtree's
in the same way.
Signed-off-by: Stephen Chung <schung@redhat.com>
To support either producing or checking manifests that are compatible
with upstream FreeBSD mtree(8) keywords, this flag will only operate on
upstream keywords. Completely ignoring non-upstream keywords, though
printing out an INFO to stderr for information purposes.
Example:
```bash
INFO: ignoring "xattrs" as it is not an upstream keyword
/set type=file nlink=1 mode=0664 uid=1000 gid=100
. size=4096 type=dir mode=0755 nlink=2 time=1469556206.235575511
[...]
```
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>