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>
Use the "slices", "maps" standard library packages, or other
readily-available features.
Should not change behavior.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
"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>
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>
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>
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>
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>
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>
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>
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>