593589
From 81308749f70d6c40c6b0fea39ffe767bfe50da38 Mon Sep 17 00:00:00 2001
593589
From: bpopovschi <zyqsempai@mail.ru>
593589
Date: Wed, 6 Nov 2019 18:20:42 +0200
593589
Subject: [PATCH] Added possibility to overwrite default tmp dir for big files
593589
593589
Signed-off-by: bpopovschi <zyqsempai@mail.ru>
593589
---
593589
 docker/archive/src.go        |  5 +++--
593589
 docker/archive/transport.go  |  4 ++--
593589
 docker/daemon/daemon_src.go  |  2 +-
593589
 docker/tarfile/dest.go       |  5 ++++-
593589
 docker/tarfile/src.go        | 20 ++++++++++++++++++--
593589
 internal/tmpdir/tmpdir.go    |  7 ++++++-
593589
 oci/archive/oci_dest.go      |  2 +-
593589
 oci/archive/oci_src.go       |  4 ++--
593589
 oci/archive/oci_transport.go |  9 +++++----
593589
 storage/storage_image.go     |  4 ++--
593589
 storage/storage_reference.go |  2 +-
593589
 types/types.go               |  3 ++-
593589
 12 files changed, 47 insertions(+), 20 deletions(-)
593589
593589
diff --git a/docker/archive/src.go b/docker/archive/src.go
593589
index a90707437..6a628508d 100644
593589
--- a/vendor/github.com/containers/image/v5/docker/archive/src.go
593589
+++ b/vendor/github.com/containers/image/v5/docker/archive/src.go
593589
@@ -2,6 +2,7 @@ package archive
593589
 
593589
 import (
593589
 	"context"
593589
+
593589
 	"github.com/containers/image/v5/docker/tarfile"
593589
 	"github.com/containers/image/v5/types"
593589
 	"github.com/sirupsen/logrus"
593589
@@ -14,11 +15,11 @@ type archiveImageSource struct {
593589
 
593589
 // newImageSource returns a types.ImageSource for the specified image reference.
593589
 // The caller must call .Close() on the returned ImageSource.
593589
-func newImageSource(ctx context.Context, ref archiveReference) (types.ImageSource, error) {
593589
+func newImageSource(ctx context.Context, sys *types.SystemContext, ref archiveReference) (types.ImageSource, error) {
593589
 	if ref.destinationRef != nil {
593589
 		logrus.Warnf("docker-archive: references are not supported for sources (ignoring)")
593589
 	}
593589
-	src, err := tarfile.NewSourceFromFile(ref.path)
593589
+	src, err := tarfile.NewSourceFromFileWithContext(sys, ref.path)
593589
 	if err != nil {
593589
 		return nil, err
593589
 	}
593589
diff --git a/docker/archive/transport.go b/docker/archive/transport.go
593589
index 44213bb8d..46c01891f 100644
593589
--- a/vendor/github.com/containers/image/v5/docker/archive/transport.go
593589
+++ b/vendor/github.com/containers/image/v5/docker/archive/transport.go
593589
@@ -134,7 +134,7 @@ func (ref archiveReference) PolicyConfigurationNamespaces() []string {
593589
 // verify that UnparsedImage, and convert it into a real Image via image.FromUnparsedImage.
593589
 // WARNING: This may not do the right thing for a manifest list, see image.FromSource for details.
593589
 func (ref archiveReference) NewImage(ctx context.Context, sys *types.SystemContext) (types.ImageCloser, error) {
593589
-	src, err := newImageSource(ctx, ref)
593589
+	src, err := newImageSource(ctx, sys, ref)
593589
 	if err != nil {
593589
 		return nil, err
593589
 	}
593589
@@ -144,7 +144,7 @@ func (ref archiveReference) NewImage(ctx context.Context, sys *types.SystemConte
593589
 // NewImageSource returns a types.ImageSource for this reference.
593589
 // The caller must call .Close() on the returned ImageSource.
593589
 func (ref archiveReference) NewImageSource(ctx context.Context, sys *types.SystemContext) (types.ImageSource, error) {
593589
-	return newImageSource(ctx, ref)
593589
+	return newImageSource(ctx, sys, ref)
593589
 }
593589
 
593589
 // NewImageDestination returns a types.ImageDestination for this reference.
593589
diff --git a/docker/daemon/daemon_src.go b/docker/daemon/daemon_src.go
593589
index 46fbcc4e0..2bca16866 100644
593589
--- a/vendor/github.com/containers/image/v5/docker/daemon/daemon_src.go
593589
+++ b/vendor/github.com/containers/image/v5/docker/daemon/daemon_src.go
593589
@@ -40,7 +40,7 @@ func newImageSource(ctx context.Context, sys *types.SystemContext, ref daemonRef
593589
 	}
593589
 	defer inputStream.Close()
593589
 
593589
-	src, err := tarfile.NewSourceFromStream(inputStream)
593589
+	src, err := tarfile.NewSourceFromStreamWithSystemContext(sys, inputStream)
593589
 	if err != nil {
593589
 		return nil, err
593589
 	}
593589
diff --git a/docker/tarfile/dest.go b/docker/tarfile/dest.go
593589
index b02c60bb3..7b2f0e418 100644
593589
--- a/vendor/github.com/containers/image/v5/docker/tarfile/dest.go
593589
+++ b/vendor/github.com/containers/image/v5/docker/tarfile/dest.go
593589
@@ -29,6 +29,7 @@ type Destination struct {
593589
 	// Other state.
593589
 	blobs  map[digest.Digest]types.BlobInfo // list of already-sent blobs
593589
 	config []byte
593589
+	sysCtx *types.SystemContext
593589
 }
593589
 
593589
 // NewDestination returns a tarfile.Destination for the specified io.Writer.
593589
@@ -94,12 +95,14 @@ func (d *Destination) HasThreadSafePutBlob() bool {
593589
 // WARNING: The contents of stream are being verified on the fly.  Until stream.Read() returns io.EOF, the contents of the data SHOULD NOT be available
593589
 // to any other readers for download using the supplied digest.
593589
 // If stream.Read() at any time, ESPECIALLY at end of input, returns an error, PutBlob MUST 1) fail, and 2) delete any data stored so far.
593589
+// Deprecated: Please use PutBlobWithSystemContext which will allows you to configure temp directory
593589
+// for big files through SystemContext.BigFilesTemporaryDir
593589
 func (d *Destination) PutBlob(ctx context.Context, stream io.Reader, inputInfo types.BlobInfo, cache types.BlobInfoCache, isConfig bool) (types.BlobInfo, error) {
593589
 	// Ouch, we need to stream the blob into a temporary file just to determine the size.
593589
 	// When the layer is decompressed, we also have to generate the digest on uncompressed datas.
593589
 	if inputInfo.Size == -1 || inputInfo.Digest.String() == "" {
593589
 		logrus.Debugf("docker tarfile: input with unknown size, streaming to disk first ...")
593589
-		streamCopy, err := ioutil.TempFile(tmpdir.TemporaryDirectoryForBigFiles(), "docker-tarfile-blob")
593589
+		streamCopy, err := ioutil.TempFile(tmpdir.TemporaryDirectoryForBigFiles(d.sysCtx), "docker-tarfile-blob")
593589
 		if err != nil {
593589
 			return types.BlobInfo{}, err
593589
 		}
593589
diff --git a/docker/tarfile/src.go b/docker/tarfile/src.go
593589
index ad0a3d2cb..3ea5ce053 100644
593589
--- a/vendor/github.com/containers/image/v5/docker/tarfile/src.go
593589
+++ b/vendor/github.com/containers/image/v5/docker/tarfile/src.go
593589
@@ -46,7 +46,14 @@ type layerInfo struct {
593589
 // 	To do for both the NewSourceFromFile and NewSourceFromStream functions
593589
 
593589
 // NewSourceFromFile returns a tarfile.Source for the specified path.
593589
+// Deprecated: Please use NewSourceFromFileWithContext which will allows you to configure temp directory
593589
+// for big files through SystemContext.BigFilesTemporaryDir
593589
 func NewSourceFromFile(path string) (*Source, error) {
593589
+	return NewSourceFromFileWithContext(nil, path)
593589
+}
593589
+
593589
+// NewSourceFromFileWithContext returns a tarfile.Source for the specified path.
593589
+func NewSourceFromFileWithContext(sys *types.SystemContext, path string) (*Source, error) {
593589
 	file, err := os.Open(path)
593589
 	if err != nil {
593589
 		return nil, errors.Wrapf(err, "error opening file %q", path)
593589
@@ -65,16 +72,25 @@ func NewSourceFromFile(path string) (*Source, error) {
593589
 			tarPath: path,
593589
 		}, nil
593589
 	}
593589
-	return NewSourceFromStream(stream)
593589
+	return NewSourceFromStreamWithSystemContext(sys, stream)
593589
 }
593589
 
593589
 // NewSourceFromStream returns a tarfile.Source for the specified inputStream,
593589
 // which can be either compressed or uncompressed. The caller can close the
593589
 // inputStream immediately after NewSourceFromFile returns.
593589
+// Deprecated: Please use NewSourceFromStreamWithSystemContext which will allows you to configure
593589
+// temp directory for big files through SystemContext.BigFilesTemporaryDir
593589
 func NewSourceFromStream(inputStream io.Reader) (*Source, error) {
593589
+	return NewSourceFromStreamWithSystemContext(nil, inputStream)
593589
+}
593589
+
593589
+// NewSourceFromStreamWithSystemContext returns a tarfile.Source for the specified inputStream,
593589
+// which can be either compressed or uncompressed. The caller can close the
593589
+// inputStream immediately after NewSourceFromFile returns.
593589
+func NewSourceFromStreamWithSystemContext(sys *types.SystemContext, inputStream io.Reader) (*Source, error) {
593589
 	// FIXME: use SystemContext here.
593589
 	// Save inputStream to a temporary file
593589
-	tarCopyFile, err := ioutil.TempFile(tmpdir.TemporaryDirectoryForBigFiles(), "docker-tar")
593589
+	tarCopyFile, err := ioutil.TempFile(tmpdir.TemporaryDirectoryForBigFiles(sys), "docker-tar")
593589
 	if err != nil {
593589
 		return nil, errors.Wrap(err, "error creating temporary file")
593589
 	}
593589
diff --git a/internal/tmpdir/tmpdir.go b/internal/tmpdir/tmpdir.go
593589
index 8c776929c..a3081f4f2 100644
593589
--- a/vendor/github.com/containers/image/v5/internal/tmpdir/tmpdir.go
593589
+++ b/vendor/github.com/containers/image/v5/internal/tmpdir/tmpdir.go
593589
@@ -3,6 +3,8 @@ package tmpdir
593589
 import (
593589
 	"os"
593589
 	"runtime"
593589
+
593589
+	"github.com/containers/image/v5/types"
593589
 )
593589
 
593589
 // unixTempDirForBigFiles is the directory path to store big files on non Windows systems.
593589
@@ -18,7 +20,10 @@ const builtinUnixTempDirForBigFiles = "/var/tmp"
593589
 // TemporaryDirectoryForBigFiles returns a directory for temporary (big) files.
593589
 // On non Windows systems it avoids the use of os.TempDir(), because the default temporary directory usually falls under /tmp
593589
 // which on systemd based systems could be the unsuitable tmpfs filesystem.
593589
-func TemporaryDirectoryForBigFiles() string {
593589
+func TemporaryDirectoryForBigFiles(sys *types.SystemContext) string {
593589
+	if sys != nil && sys.BigFilesTemporaryDir != "" {
593589
+		return sys.BigFilesTemporaryDir
593589
+	}
593589
 	var temporaryDirectoryForBigFiles string
593589
 	if runtime.GOOS == "windows" {
593589
 		temporaryDirectoryForBigFiles = os.TempDir()
593589
diff --git a/oci/archive/oci_dest.go b/oci/archive/oci_dest.go
593589
index 164d5522d..6918f7fb0 100644
593589
--- a/vendor/github.com/containers/image/v5/oci/archive/oci_dest.go
593589
+++ b/vendor/github.com/containers/image/v5/oci/archive/oci_dest.go
593589
@@ -19,7 +19,7 @@ type ociArchiveImageDestination struct {
593589
 
593589
 // newImageDestination returns an ImageDestination for writing to an existing directory.
593589
 func newImageDestination(ctx context.Context, sys *types.SystemContext, ref ociArchiveReference) (types.ImageDestination, error) {
593589
-	tempDirRef, err := createOCIRef(ref.image)
593589
+	tempDirRef, err := createOCIRef(sys, ref.image)
593589
 	if err != nil {
593589
 		return nil, errors.Wrapf(err, "error creating oci reference")
593589
 	}
593589
diff --git a/oci/archive/oci_src.go b/oci/archive/oci_src.go
593589
index 33a41d44b..363c12b0b 100644
593589
--- a/vendor/github.com/containers/image/v5/oci/archive/oci_src.go
593589
+++ b/vendor/github.com/containers/image/v5/oci/archive/oci_src.go
593589
@@ -20,7 +20,7 @@ type ociArchiveImageSource struct {
593589
 // newImageSource returns an ImageSource for reading from an existing directory.
593589
 // newImageSource untars the file and saves it in a temp directory
593589
 func newImageSource(ctx context.Context, sys *types.SystemContext, ref ociArchiveReference) (types.ImageSource, error) {
593589
-	tempDirRef, err := createUntarTempDir(ref)
593589
+	tempDirRef, err := createUntarTempDir(sys, ref)
593589
 	if err != nil {
593589
 		return nil, errors.Wrap(err, "error creating temp directory")
593589
 	}
593589
@@ -43,7 +43,7 @@ func LoadManifestDescriptor(imgRef types.ImageReference) (imgspecv1.Descriptor,
593589
 	if !ok {
593589
 		return imgspecv1.Descriptor{}, errors.Errorf("error typecasting, need type ociArchiveReference")
593589
 	}
593589
-	tempDirRef, err := createUntarTempDir(ociArchRef)
593589
+	tempDirRef, err := createUntarTempDir(nil, ociArchRef)
593589
 	if err != nil {
593589
 		return imgspecv1.Descriptor{}, errors.Wrap(err, "error creating temp directory")
593589
 	}
593589
diff --git a/oci/archive/oci_transport.go b/oci/archive/oci_transport.go
593589
index 2d72a6fee..b7780abde 100644
593589
--- a/vendor/github.com/containers/image/v5/oci/archive/oci_transport.go
593589
+++ b/vendor/github.com/containers/image/v5/oci/archive/oci_transport.go
593589
@@ -159,8 +159,9 @@ func (t *tempDirOCIRef) deleteTempDir() error {
593589
 }
593589
 
593589
 // createOCIRef creates the oci reference of the image
593589
-func createOCIRef(image string) (tempDirOCIRef, error) {
593589
-	dir, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(), "oci")
593589
+// If SystemContext.BigFilesTemporaryDir not "", overrides the temporary directory to use for storing big files
593589
+func createOCIRef(sys *types.SystemContext, image string) (tempDirOCIRef, error) {
593589
+	dir, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(sys), "oci")
593589
 	if err != nil {
593589
 		return tempDirOCIRef{}, errors.Wrapf(err, "error creating temp directory")
593589
 	}
593589
@@ -174,8 +175,8 @@ func createOCIRef(image string) (tempDirOCIRef, error) {
593589
 }
593589
 
593589
 // creates the temporary directory and copies the tarred content to it
593589
-func createUntarTempDir(ref ociArchiveReference) (tempDirOCIRef, error) {
593589
-	tempDirRef, err := createOCIRef(ref.image)
593589
+func createUntarTempDir(sys *types.SystemContext, ref ociArchiveReference) (tempDirOCIRef, error) {
593589
+	tempDirRef, err := createOCIRef(sys, ref.image)
593589
 	if err != nil {
593589
 		return tempDirOCIRef{}, errors.Wrap(err, "error creating oci reference")
593589
 	}
593589
diff --git a/storage/storage_image.go b/storage/storage_image.go
593589
index 2b89f329f..409619b21 100644
593589
--- a/vendor/github.com/containers/image/v5/storage/storage_image.go
593589
+++ b/vendor/github.com/containers/image/v5/storage/storage_image.go
593589
@@ -341,8 +341,8 @@ func (s *storageImageSource) GetSignatures(ctx context.Context, instanceDigest *
593589
 
593589
 // newImageDestination sets us up to write a new image, caching blobs in a temporary directory until
593589
 // it's time to Commit() the image
593589
-func newImageDestination(imageRef storageReference) (*storageImageDestination, error) {
593589
-	directory, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(), "storage")
593589
+func newImageDestination(sys *types.SystemContext, imageRef storageReference) (*storageImageDestination, error) {
593589
+	directory, err := ioutil.TempDir(tmpdir.TemporaryDirectoryForBigFiles(sys), "storage")
593589
 	if err != nil {
593589
 		return nil, errors.Wrapf(err, "error creating a temporary directory")
593589
 	}
593589
diff --git a/storage/storage_reference.go b/storage/storage_reference.go
593589
index 4e137ad1b..9eb0ae738 100644
593589
--- a/vendor/github.com/containers/image/v5/storage/storage_reference.go
593589
+++ b/vendor/github.com/containers/image/v5/storage/storage_reference.go
593589
@@ -295,5 +295,5 @@ func (s storageReference) NewImageSource(ctx context.Context, sys *types.SystemC
593589
 }
593589
 
593589
 func (s storageReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
593589
-	return newImageDestination(s)
593589
+	return newImageDestination(sys, s)
593589
 }
593589
diff --git a/types/types.go b/types/types.go
593589
index aaeb97da6..13a8ef78d 100644
593589
--- a/vendor/github.com/containers/image/v5/types/types.go
593589
+++ b/vendor/github.com/containers/image/v5/types/types.go
593589
@@ -490,9 +490,10 @@ type SystemContext struct {
593589
 	OSChoice string
593589
 	// If not "", overrides the system's default directory containing a blob info cache.
593589
 	BlobInfoCacheDir string
593589
-
593589
 	// Additional tags when creating or copying a docker-archive.
593589
 	DockerArchiveAdditionalTags []reference.NamedTagged
593589
+	// If not "", overrides the temporary directory to use for storing big files
593589
+	BigFilesTemporaryDir string
593589
 
593589
 	// === OCI.Transport overrides ===
593589
 	// If not "", a directory containing a CA certificate (ending with ".crt"),
593589
From b65de0f71c33ae1d3558132261f159e321c8edf1 Mon Sep 17 00:00:00 2001
593589
From: Matthew Heon <mheon@redhat.com>
593589
Date: Mon, 17 Aug 2020 09:24:41 -0400
593589
Subject: [PATCH] Add support for setting the large files tmpdir to v1.6
593589
593589
This is based on 2c328f94b61116bfa7d1d46525d854678f94c9f3 by Les
593589
Aker, and e53fc16b9f470a137abf182b0561a16447bfd5b7 by Dan Walsh
593589
(the latter from containers/buildah). They have been merge here
593589
to allow this to compile on the older v1.6 branch of Podman.
593589
593589
Unfortunately this does not fix Buildah, as the Buildah patches
593589
are too new to apply on top of this old branch.
593589
593589
Signed-off-by: Matthew Heon <mheon@redhat.com>
593589
---
593589
 libpod/image/docker_registry_options.go | 11 ++++++++++-
593589
 1 file changed, 10 insertions(+), 1 deletion(-)
593589
593589
diff --git a/libpod/image/docker_registry_options.go b/libpod/image/docker_registry_options.go
593589
index 62a4af4653..b1eb31e2db 100644
593589
--- a/libpod/image/docker_registry_options.go
593589
+++ b/libpod/image/docker_registry_options.go
593589
@@ -2,10 +2,10 @@ package image
593589
 
593589
 import (
593589
 	"fmt"
593589
+	"os"
593589
 
593589
 	"github.com/containers/image/v5/docker/reference"
593589
 	"github.com/containers/image/v5/types"
593589
-
593589
 	podmanVersion "github.com/containers/libpod/version"
593589
 )
593589
 
593589
@@ -41,6 +41,7 @@ func (o DockerRegistryOptions) GetSystemContext(parent *types.SystemContext, add
593589
 		DockerArchiveAdditionalTags: additionalDockerArchiveTags,
593589
 		OSChoice:                    o.OSChoice,
593589
 		ArchitectureChoice:          o.ArchitectureChoice,
593589
+		BigFilesTemporaryDir:        GetTempDir(),
593589
 	}
593589
 	if parent != nil {
593589
 		sc.SignaturePolicyPath = parent.SignaturePolicyPath
593589
@@ -65,3 +66,11 @@ func GetSystemContext(signaturePolicyPath, authFilePath string, forceCompress bo
593589
 
593589
 	return sc
593589
 }
593589
+
593589
+// Retrieve the temporary directory for storing large files.
593589
+func GetTempDir() string {
593589
+	if tmpdir, ok := os.LookupEnv("TMPDIR"); ok {
593589
+		return tmpdir
593589
+	}
593589
+	return "/var/tmp"
593589
+}