Commit Graph

17 Commits

Author SHA1 Message Date
Giuseppe Scrivano 84e750286e
check: adapt to work with ForceMask
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-12-06 08:50:08 +01:00
Kir Kolyshkin fd5483f4a8 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č 35b3e0f41b 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č 751c13d2a0 Use slices.Clone where appropriate
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 19:44:47 +02:00
Miloslav Trmač e4833c3df2 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 e6c132bd00
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 b90afbd788
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 faf436d108 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 79b8f9401e 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 6d787b262b 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 fcbc27aa12 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 b0f85f7ccd 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 9ef716b9ed 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č 2e581d5fb4 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č 087bc924d6 Use generics in readAllImageStores
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-18 21:25:04 +02:00
Miloslav Trmač 0a417fe0bb Use generics in readAllLayerStores
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-18 21:24:30 +02:00
Nalin Dahyabhai cabf1b9fd0 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