1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-09-13 13:53:20 +00:00
Commit graph

27 commits

Author SHA1 Message Date
Aleksa Sarai
604ab42863
compare: improve tar_time truncation
Rather than parsing the value as a float and then truncating it, just
parse it as an integer in the first place (this also adds some
validation that we are parsing a reasonable-looking value).

While we're at it, add some integration tests for this code to make sure
this quite complicated special-case behaviour doesn't regress.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-09 22:48:56 +10:00
Aleksa Sarai
0beb885cbf
compare: properly compare tar_time and time
In certain circumstances, if a manifest with "time" keywords was
compared to another manifest with "tar_time" keywords, differences were
not actually reported despite there being logic for it.

Unfortunately, even though commit 26ff922da6 ("compare: implement
mtree.DirectoryHierarchy comparisons") explicitly included logic to
handle the necessary "time" -> "tar_time" conversions, the same commit
also made it so that Compare() could be instructed to only consider a
subset of keywords and failed to take into account said "time" ->
"tar_time" remapping.

Most users have likely not noticed this because gomtree will re-use the
keywords from a manifest when doing a straightforward "gomtree validate"
invocation, but if you explicitly requested "time" when validating a
"tar_time" manifest (and *not* the other way around) then any time
changes would be undetected.

Fixes: 26ff922da6 ("compare: implement mtree.DirectoryHierarchy comparisons")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-09 22:47:49 +10:00
Aleksa Sarai
945eeeda2d
tests: cli: properly check for exit status codes in error cases
POSIX explicitly requires "set -e" to NOT treat "! cmd" as an error even
if fails[1]:

> The -e setting shall be ignored when executing the compound list
> following the while, until, if, or elif reserved word, *a pipeline
> beginning with the ! reserved word*, or any command of an AND-OR list
> other than the last. *[emphasis added]*

And bash has similar documentation on this behaviour[2].

This means that our tests were completely ineffective at detecting error
codes from gomtree, and as a result we did not detect the regression in
commit 83c9fdb78b ("refactor: prefactor for adding new subcommands").

The simplest solution (as done in this patch) is to just wrap all of the
failing examples in a subshell, which causes the shell to no longer
consider them exempt from "set -e". A more complete solution would be to
either switch to something like bats entirely or at least use something
like their "run" helper function to test for exit status codes
correctly.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
[2]: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

Fixes: 5d7f6c36e0 ("walk: directory is expected to be walked. A file is not.")
Fixes: 2d841d54bf ("test: testing the double -f comparison")
Fixes: f6c295f2e9 ("test: cli: add unicode verification test")
Fixes: 071977cef6 ("test: cli: add xattr tests")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-08 23:53:21 +10:00
e19072ac1c
*: begin incorporating the "validate" subcommand
Update the README to show the validate subcommand by default.
This doesn't eliminate the default behavior of _not_ using the command,
but begins the visibility of using it by default.

Also copy one of the existing tests, to ensure the same behaviour works
as we add more subcommands and/or global flags.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2023-10-24 10:25:18 -04:00
42b655d8ee
*.go: update to golangci-lint, and fix everything
install tools in the workflow actions
Also switch away from deprecated ioutil

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2023-10-23 21:59:44 -04:00
thesayyn
83c9fdb78b
refactor: prefactor for adding new subcommands 2023-10-20 16:12:08 -07:00
5d7f6c36e0
walk: directory is expected to be walked. A file is not.
Fixes: #166

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2022-04-23 13:40:44 -04:00
2d841d54bf
test: testing the double -f comparison
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2022-04-04 18:13:23 -04:00
f32ba81c5e
*: rework the test tools, so no dep is ignored
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2022-04-03 23:15:40 -04:00
37d776ac40
cli.test: colorize the success/failure
updating and adding vendored source to do it

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2018-08-20 07:57:14 -04:00
f34a2e0d2b test/cli: and a newline 2018-08-13 21:56:19 -04:00
dce9629991 test/cli: add a success message 2018-08-13 21:54:55 -04:00
68a6d43233 test/cli: fixup for supporting OSX 2018-08-13 21:20:31 -04:00
f271d65127
cli.test: don't have -k in the print
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-06-30 15:34:53 -04:00
Aleksa Sarai
f6c295f2e9
test: cli: add unicode verification test
This wraps up the govis changes. While umoci has much more hardcore
tests for unicode, this is done to ensure that go-mtree won't break
before its vendored into umoci.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-02-16 09:28:21 +11:00
b7967864aa
cli.test: failing test on stdin manifest
behavior ought to be, when `-f <file>` is not provided, then expect the
manifest to be provided on stdin.
Currently gomtree just fails if there is no `-f` (and it is not `-c`)

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-01-20 13:08:15 -05:00
235566d9e0
cli.test: passthrough and use TMPDIR
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-01-20 11:30:54 -05:00
b71ad0f21e
cli.test: setting xattr requires a value
this early check was not valid as it required a value before it would
attempt to set the xattr

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-01-20 11:16:38 -05:00
Aleksa Sarai
071977cef6
test: cli: add xattr tests
Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-01-17 00:48:06 +11:00
Aleksa Sarai
3c76a35588
test: cli: add information about which test failed
Signed-off-by: Aleksa Sarai <asarai@suse.de>
2017-01-17 00:46:28 +11:00
e2640e6dfa
cli.test: add case from #90
Closes #90

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-30 21:41:39 -05:00
f49f66f61e
cli.test: fail on cli tests
This cleans up the Makefile target, and drops the dependency to point to
the $root path of the repo.

Fixes https://github.com/vbatts/go-mtree/issues/98

Reported-by: Aleksa Sarai <asarai@suse.de>
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-22 10:57:47 -05:00
c0a5cb25ec
-d: exclude non-directories
Adding flag, and supporting functionality for exluding entries that are
non-directories

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-17 22:43:02 -05:00
21723a3974
*: fix comparison of missing keywords
Adding another test validated from the FreeBSD workflow.

Just because the keywords requested to be validated are not present in
the manifest, it is not an error.
Also, if the keywords from a new manifest are not present in a prior
manifest, then only compare the common keywords.

Fixes https://github.com/vbatts/go-mtree/issues/86

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-17 21:38:10 -05:00
5d26726bb1
keyword: unify keyword synonyms
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-16 15:42:53 -05:00
Aleksa Sarai
704d91fc7c
keywords: safely encode symlink keywords
symlink(2) is a very dumb syscall, and allows you to put any damn value
you please inside a symlink. In addition, spaces are valid path
characters which causes issues with keyword parsing. So use Vis() and
Unvis() to safely store an encoded version of the path.

This also adds a cli test for this behaviour.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-11-12 01:52:37 +11:00
b83c40e7f9
test: add basic cli test
tar and filesystem check

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2016-11-07 10:40:12 -05:00