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.
This commit is contained in:
Owen W. Taylor
2024-11-06 09:09:07 -05:00
committed by Simon McVittie
parent 73dd78f775
commit 35995290f5

View File

@@ -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);