1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-28 19:15:40 +00:00
Commit graph

262 commits

Author SHA1 Message Date
90bdfb6c29 gomtree: allow tar from stdin
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-08-11 14:07:07 -04:00
232b80f320 Merge pull request #63 from stephen679/resolve_hardlinks
tar: resolve hardlinks when streaming archive
2016-08-11 13:39:28 -04:00
Stephen Chung
5837d00b07 tar: resolve hardlinks when streaming archive
Fill in the data of the Entry with the data of the
file that a hardlink actually represents.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-08-11 13:24:44 -04:00
ea6c6eff1b Merge pull request #57 from stephen679/tar_symlink_size
keywords: return non-zero symlink size
2016-08-11 12:44:03 -04:00
7dbe113002 Merge pull request #62 from stephen679/evaluating_symlink
check: functionality for symlinks
2016-08-10 15:22:32 -04:00
Stephen Chung
2facedc401 check: functionality for symlinks
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>
2016-08-10 15:01:07 -04:00
d6b0881515 Merge pull request #61 from vbatts/clearer_branch
tar: more clear `if` predicate
2016-08-10 14:02:02 -04:00
2a99b062a7 tar: more clear if predicate
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-08-10 13:46:14 -04:00
48e7ab8031 Merge pull request #54 from stephen679/keywords-used-list
hierarchy: provide option to list the used keywords in a spec
2016-08-10 13:35:46 -04:00
71abbd944f Merge pull request #55 from stephen679/refactor_tar
tar: refactoring and resolve race condition
2016-08-10 13:31:53 -04:00
Stephen Chung
00a4a2e674 tar: remove "time" keyword before tree creation
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>
2016-08-10 13:17:16 -04:00
Stephen Chung
3d6b74d6f7 tar: populate Entry tree under a common root
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>
2016-08-09 12:09:36 -04:00
Stephen Chung
5372b5fc47 hierarchy: provide option to list the used keywords in a spec
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>
2016-08-05 10:50:54 -04:00
Stephen Chung
4dc5000106 keywords: return non-zero symlink size
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>
2016-08-02 15:39:54 -04:00
Stephen Chung
6a37331074 tar: flatten the pseudo-tree only after readHeaders() is done
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>
2016-08-02 11:42:02 -04:00
Stephen Chung
822f319224 tar: minor refactoring of populateTree and flatten
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>
2016-07-31 22:26:55 -04:00
aa6d7c2c6e Merge pull request #53 from vbatts/xattrs_base64
keywords: switch 'xattr' to base64
2016-07-27 18:40:15 -04:00
7e2ed0b70b keywords: switch 'xattr' to base64
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>
2016-07-27 18:38:10 -04:00
27459241ae Merge pull request #51 from stephen679/readme-with-tar
readme: update details about go-mtree in readme
2016-07-27 18:34:39 -04:00
Stephen Chung
a320d77a6f readme: update details about go-mtree in readme
Include details about tar compatibility, as well as
other aspects that have changed

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-27 18:11:34 -04:00
94f9a10253 Merge pull request #49 from stephen679/full_digest_output
keywords: synonyms of keywords should produce same output
2016-07-27 15:24:39 -04:00
Stephen Chung
877272303b keywords: synonyms of keywords should produce same output
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>
2016-07-27 10:59:58 -04:00
3d7e24b48a Merge pull request #45 from vbatts/bsd_keywords
Bsd keywords
2016-07-26 16:48:49 -04:00
919d71c105 main: add -bsd-keywords
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>
2016-07-26 14:31:39 -04:00
b790afae01 keywords: include list of upstream keywords
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-26 14:21:44 -04:00
664ad32ff6 Merge pull request #44 from vbatts/xattrs
fix xattr ERANGE
2016-07-26 14:03:16 -04:00
2685cd3cc5 xattr: fix the failure on empty list
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-26 13:55:25 -04:00
ed6b293839 debug: add an mtree.Debugf and -debug flag
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-26 13:54:45 -04:00
39f68f5be2 Merge pull request #41 from stephen679/fix_too_many_files_open
[bug fix] tar: explicitly close files after populateTree
2016-07-26 11:56:57 -04:00
2324bb8b19 Merge pull request #42 from stephen679/fix_no_arguments
cmd: gomtree no arguments
2016-07-26 11:52:03 -04:00
e31036f7e3 Merge pull request #39 from stephen679/no_duplicate_keywords
main: don't dupliate keywords
2016-07-26 11:35:43 -04:00
Stephen Chung
8e3e4c3651 cmd: gomtree no arguments
my tar_stream_tar_time PR accidentally put the functionality
for when gomtree has no arguments inside an unreachable block.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-25 20:35:38 -04:00
Stephen Chung
767d4bbb4b tar: explicitly close files after populateTree
Files don't close properly when `defer`ing inside
a for loop, since the surrounding function is still
iterating in a for loop. To fix this, just close the files
explicitly after `populateTree()` in `readHeaders()`

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-25 20:04:55 -04:00
b0c1606133 Merge pull request #37 from vbatts/no_null_json
check: omitempty rather than `null`
2016-07-25 18:51:38 -04:00
Stephen Chung
843517f136 main: don't dupliate keywords
When adding keywords with -K, we don't want to
duplicate keywords in the keywords slice.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-25 18:29:10 -04:00
c74c2ed6d7 Merge pull request #38 from stephen679/vis
vis: refactor code to use Vis() and Unvis()
2016-07-25 17:59:48 -04:00
Stephen Chung
773763fb87 vis: refactored code to reflect using vis/unvis for file names
Added some more test cases for `vis`ing and `unvis`ing
strings, and a test case that walks/checks a directory with
filenames that require encoding. Had to change Path() to account
for possible errors Unvis() could return. Refactored Vis()/Unvis() into
go-mtree tar functionality as well.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-25 16:41:06 -04:00
898661f983 check: omitempty rather than null
When using `-result-format=json` flag, just show populated fields.

Before:
```bash
$ gomtree -result-format=json -p ./bin -f ./bin.mtree
{"failures":[{"path":"gomtree","keyword":"size","expected":"2646101","got":"2930231"}],"Missing":null,"Extra":null}
```

After:
```bash
$ gomtree -result-format=json -p ./bin -f ./bin.mtree
{"failures":[{"path":"gomtree","keyword":"size","expected":"2646101","got":"2930231"}]}
```

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-25 15:39:55 -04:00
a63f83d94d vis/unvis: pull in exact implementation from FreeBSD
Perhaps this is not completely ideal, because it brings in cgo.
And with the flags, it can have tailored experience.

I've added a basic test to ensure that the cases we're interested in are
covered.

This does not yet integrate the usage of Vis()/Unviz() into the manifest
create and compare.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-25 15:36:29 -04:00
cc939615c7 Merge pull request #29 from stephen679/tree_tar_stream
*: creating validation manifest from archive and validating a manifest against archive
2016-07-25 15:14:56 -04:00
Stephen Chung
656e577ecc *: have gomtree always evaluate tar_time if it is present
if the keyword "tar_time" is present when evaluating
an Entry, gomtree should use the tar_time when evaluating
the "time" keyword as well. This commit also adds a test that
makes sure "tar_time" wins against "time" if both are present.
Some minor clean-ups as well, such as checking if KeywordFunc[keyword]
actually retrieves a function.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-23 12:07:43 -04:00
bc6f3bf902 tar_time: treat time from tar archives special
Since the field in a tar header for each file only preserves seconds
precision, not nanosecond precision, let's handle it special. This will
allow for more custom case handling in Check()

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-23 12:07:43 -04:00
Stephen Chung
decc72b335 tar: create and validate a manifest from a tar stream
This commit contains added features to go-mtree that allows
user to create an mtree spec with '-T' option when specifying
a tar archive. Users can also validate an mtree spec against
a tar archive with an mtree spec. Also for the test archive,
there is a mixture of files, and folders (empty & non-empty),
and symlinks (broken & unbroken).

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-23 12:07:43 -04:00
Stephen Chung
f0f15a0e49 keywords: return "link" keyword along with its value
Originally only returning `Sys.linkname` when evaluating
a tar header's link field. We want it to be in the form of
keyword=value instead.

Signed-off-by: Stephen Chung <schung@redhat.com>
2016-07-23 12:07:43 -04:00
faa80931af *: refactoring to support streams
when creating a manifest from, or validating, a stream like a tar
archive, it requires thinking about some of the functions differently
than walking a directory tree.

This is the beginning of allowing for such features.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-07-23 12:07:43 -04:00
e6bdb36de3 Merge pull request #31 from cyphar/alternate-formats
cmd: add alternate formats
2016-07-22 17:39:24 -04:00
Aleksa Sarai
119cdc314c
cmd: add --result-format=path format
This allows for shell callers to just get a simple diff of what files
changed between the two invocations of go-mtree. This is somewhat
similar to supplying -f twice to the BSD mtree (though that compares two
specs and also gives you information about what *kind* of change
occurred).

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-07-22 20:06:32 +10:00
Aleksa Sarai
692f56a830
*: add --result-format=json format
This is far easier to parse than the default raw format, and provides
the full serialised result structure.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-07-22 20:06:32 +10:00
Aleksa Sarai
8cf7253132
cmd: add --result-format
This allows callers to deal with multiple output formats and not require
string parsing in order to understand what the error was. The default
format is "bsd".

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-07-22 20:06:26 +10:00
20279bacf2 Merge pull request #35 from stephen679/set_keyword_selector
[bug fix] walk: filter \set keyword correctly
2016-07-21 13:51:47 -04:00