From 35995290f57d3ee3379cf78f9eacda4abb73cdbf Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Wed, 6 Nov 2024 09:09:07 -0500 Subject: [PATCH] Add a FLATPAK_DOWNLOAD_TMPDIR variable Instead of hardcoding /var/tmp when temporarily downloading layer tarballs, support overriding with a FLATPAK_DOWNLOAD_TMPDIR environment variable. We don't use TMPDIR because the layer tarballs can be very big (in extreme cases like an SDK > 1GB), and TMPDIR is more likely to point to a in-memory tmpfs. --- common/flatpak-oci-registry.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/flatpak-oci-registry.c b/common/flatpak-oci-registry.c index c1a1b174..7badf2ab 100644 --- a/common/flatpak-oci-registry.c +++ b/common/flatpak-oci-registry.c @@ -579,9 +579,18 @@ flatpak_oci_registry_initable_init (GInitable *initable, FlatpakOciRegistry *self = FLATPAK_OCI_REGISTRY (initable); gboolean res; - if (self->tmp_dfd == -1 && - !glnx_opendirat (AT_FDCWD, "/var/tmp", TRUE, &self->tmp_dfd, error)) - return FALSE; + if (self->tmp_dfd == -1) + { + /* We don't use TMPDIR because the downloaded artifacts can be + * very big, and we want to prefer /var/tmp to /tmp. + */ + const char *tmpdir = g_getenv ("FLATPAK_DOWNLOAD_TMPDIR"); + if (tmpdir == NULL) + tmpdir = "/var/tmp"; + + if (!glnx_opendirat (AT_FDCWD, tmpdir, TRUE, &self->tmp_dfd, error)) + return FALSE; + } if (g_str_has_prefix (self->uri, "file:/")) res = flatpak_oci_registry_ensure_local (self, self->for_write, cancellable, error);