Commit Graph

17 Commits

Author SHA1 Message Date
Giuseppe Scrivano 0a70897995 check: adapt to work with ForceMask
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-12-06 08:50:08 +01:00
Kir Kolyshkin 2b6ab1ff55 all: use strings.Cut{Prefix,Suffix} where appropriate
Functions strings.CutPrefix and strings.CutSuffix are available
since Go 1.20 and can be used instead of strings.Has* counterparts
when the latter is followed by removing the prefix or suffix.

This simplifies the code a bit, allowing for less mistakes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-09-19 17:03:19 -07:00
Miloslav Trmač 92e1bd58a3 Avoid unnecessary manually-coded loops
Use the "slices", "maps" standard library packages, or other
readily-available features.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 19:45:45 +02:00
Miloslav Trmač 7c8a73dd5d Use slices.Clone where appropriate
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 19:44:47 +02:00
Miloslav Trmač 8d386c3046 Reorder a switch to satisfy staticcheck
"default case should be first or last in switch statement (ST1015)"

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-10 23:54:30 +02:00
Jan Rodák f07249e5ae Fix errcheck: error return value of `io.Copy` is not checked
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-07-09 16:58:10 +02:00
Giuseppe Scrivano a5dbb36610 check: mount layer as read-only
mount the image as read-only so it can work also for composefs images.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-07-03 11:12:24 +02:00
Nalin Dahyabhai e20d084c26 check: be able to complain about both diff digests and sizes
When we're comparing a layer's regenerated diff against the one that was
used to initialize it, don't stop at just complaining about the digest
if the length is also coming up wrong.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:56 -04:00
Nalin Dahyabhai 7206d0f90c compareCheckDirectory: learn about ID maps
Handle old-fashioned ID mappings when looking at layers.  Nowadays,
we'll use an idmapped mount if we can, but we shouldn't blow up if we
had to chown a layer because we couldn't use an idmapped mount.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:56 -04:00
Nalin Dahyabhai f8d7ba54dd checkDirectory.headers: always process hard links last
When we use diff headers to build a structure that represents what we
expect to find when we look at a layer, make sure we process hard links
last, so that we can refer to metadata about copies of the linked-to
file from the layer whose diffs we're processing, instead of potentially
metadata about versions of those files which came from earlier layers.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:56 -04:00
Nalin Dahyabhai 9ca8244fe9 checkDirectory.add: handle "." correctly
Correctly handle path names that start with "." or "./", which are used
for changes to the root directory's permissions.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:56 -04:00
Nalin Dahyabhai fa24059235 newCheckDirectoryFromDirectory: no need to check for links
tar.FileInfoHeader() doesn't produce TypeLink entries (it's not going to
walk the filesystem to find other instances of the same inode), and
TypeRegA has been deprecated for some time, so it's a waste of time to
check for them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:56 -04:00
Nalin Dahyabhai 838ade0d2e check: suppress certain errors when pull_options might cause them
Files hard linked in from an OSTree repository won't tend to have the
right timestamps on them, so we have to accept that they'll not match
what we have on record when we're using one to speed up pulling images.

If we're ignoring chown errors when populating layers, then there's no
point in expecting the ownerships of the contents of on-disk layers to
match expectations.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-06-13 14:14:55 -04:00
Miloslav Trmač b7d9e41267 Use generics in readContainerStore
... and use it in many more places.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-18 21:25:27 +02:00
Miloslav Trmač 9538e3503b Use generics in readAllImageStores
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-18 21:25:04 +02:00
Miloslav Trmač 77bd99c0fc Use generics in readAllLayerStores
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-18 21:24:30 +02:00
Nalin Dahyabhai 92c4efc26e Initial implementation of consistency checks
Add initial Check() and Repair() methods to Stores.

Check() checks for inconsistencies between the layers which the
lower-level storage driver claims to know about and the ones which we
know we're managing.  It checks that layers referenced by layers,
images, and containers are known to us and that images referenced by
containers are known to us.  It checks that data which we store
alongside layers, images, and containers is still present, and to the
extent which we store other information about that data (frequenly just
the size of the data), verifies that it matches recorded expectations.
Lastly, it checks that layers which are part of images (and which we
therefore know what they should have in them) have the expected content,
and nothing else.

Repair() removes any containers, images, and layers which have any
errors associated with them.  This is destructive, so its use should be
considered and deliberate.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-13 10:38:24 -04:00