Commit Graph

22 Commits

Author SHA1 Message Date
Kir Kolyshkin 73b194b8ed Use for range over integers
This form is available since Go 1.22 (see
https://tip.golang.org/ref/spec#For_range) and will probably be seen
more and more in the new code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 15:39:12 -07:00
Kir Kolyshkin e1b7a98a21 Use min/max to simplify the code
Should not change functionality.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-28 20:08:32 -07:00
Miloslav Trmač 5c67136767 Move pkg/chunked/internal to pkg/chunked/internal/minimal
We now have several internal subpackages of pkg/chunked, so delineate
more explicitly the parts that should be kept as small as possible
because the c/image compression package depends on them.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-12-13 01:27:58 +01:00
Miloslav Trmač 2ba2dd1689 Split NewFileMetadata from pkg/chunked/compressor
In addition to the existing use when creating a TOC from tar data,
we will also need it when parsing TOC and tar-split data.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-18 23:36:57 +02:00
Giuseppe Scrivano cb394549cb
chunked: skip setting time if empty
do not specify the timestamps fields in the TOC if they are empty.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-07-02 14:50:51 +02:00
Jan Rodák d8c5cc5428
Fix deprecated use of hdr.Xattrs (SA1019)
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-06-26 20:12:43 +02:00
Giuseppe Scrivano 6a7ab2bc99
chunked: flush the input tarball to the output
Flush the entire input tarball to the output in the zstd:chunked
stream writer.  This is needed to include any trailing zeros that
affect the uncompressed digest.

Closes: https://github.com/containers/storage/issues/1771

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-12-13 17:31:00 +01:00
Giuseppe Scrivano b0986ebb6b
chunked: close reader pipe before waiting for errors
close the pipe immediately when the file is closed to avoid a possible
deadlock if the other end is waiting for EOF on the writer side.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-12-13 17:30:56 +01:00
Giuseppe Scrivano 7bbf6ed448
chunked: generate tar-split as part of zstd:chunked
change the file format to store the tar-split as part of the
zstd:chunked image.  This will allow clients to rebuild the entire
tarball without having to download it fully.

also store the uncompressed digest for the tarball, so that it can be
stored into the storage database.

Needs: https://github.com/containers/image/pull/1976

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:39 +02:00
Giuseppe Scrivano c3d13cca2e
chunked: drop superfluous flush
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:39 +02:00
Kir Kolyshkin a4d8f720a2 Format sources with gofumpt
gofumpt is a superset of gofmt, enabling some more code formatting
rules.

This commit is brought to you by

	gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-26 16:17:31 -07:00
Miloslav Trmač 7f0dae6fea Rename ReadByte to readByte
It is only used internally, and this avoids a warning
about a conflict with io.ByteReader.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:53 +02:00
Miloslav Trmač 3926780ab1 Misc error handling fixes or warning silences
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-01 02:46:52 +02:00
Miloslav Trmač be449e9467 Remove unused fields from holesFinder
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:49 +02:00
Miloslav Trmač a1ccc9d862 Use os.WriteFile instead of ioutil.WriteFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:34 +02:00
Giuseppe Scrivano 33f973c732
Revert "chunked: use valyala/gozstd"
This reverts commit 5bb6d8e65e.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-17 16:16:46 +01:00
Giuseppe Scrivano 198820877c
pkg/chunked: add support for sparse files
automatically detect holes in sparse files (the threshold is hardcoded
at 1kb for now) and add this information to the manifest file.

The receiver will create a hole (using unix.Seek and unix.Ftruncate)
instead of writing the actual zeros.

Closes: https://github.com/containers/storage/issues/1091

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-13 13:32:13 +01:00
Giuseppe Scrivano 5bb6d8e65e
chunked: use valyala/gozstd
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:28:15 +01:00
Giuseppe Scrivano 54096ca870
chunked: use rolling checksum to split files
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano 315d4fb2ec
chunked: change zstd default compression level
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Giuseppe Scrivano 2855d17137
chunked: estargz support
in addition to zstd:chunked, add support for the estargz format.

estargz is maintained at github.com/containerd/stargz-snapshotter

Images using estargz can be used on old clients and registries that
have no support for the zstd compression algorithm.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-25 16:16:20 +02:00
Miloslav Trmač 92b63ead41 Split pkg/chunked.ZstdCompressor into a separate subpackage
containers/image/pkg/compression depends on that function, so it's
highly undesirable for it to drag in all of containers/storage.

So, move it into a separate subpackage, along with its exclusive
dependency tree.

Code that is called both from the new pkg/chunked/compressor
and the original pkg/chunked has been moved into pkg/chunked/internal ,
so that we don't expose any new public API. That move was made
purely mechanically without any concern for conceptual consistency,
to minimize the size of the dependency (and not to spend time on
that until the concept is proven to be useful).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-23 21:43:52 +02:00