#1135727 TMPDIR silently ignored if unwritable

#1135727#5
Date:
2026-05-05 09:11:16 UTC
From:
To:
Hi,

look:

$ TMPDIR=/var/tmp/live mmdebstrap sid /dev/null
I: automatically chosen mode: unshare
I: chroot architecture amd64 is equal to the host's architecture
I: finding correct signed-by value...
done
I: automatically chosen format: null
I: using /tmp/mmdebstrap.3sNDppTmUk as tempdir
I: running apt-get update...

I would expect "I: using /var/tmp/live as tempdir" at this point. That
works if /var/tmp/live is writeable by the local user. I guess that
mmdebstrap silently falls back to /tmp in that case It should issue a
warning or even error out.

Grüße
Marc

#1135727#10
Date:
2026-07-30 16:34:36 UTC
From:
To:
Hello,

I reproduced this issue against mmdebstrap 1.5.7-3.

The fallback comes from File::Temp::tempdir(..., TMPDIR => 1), which delegates directory selection to File::Spec->tmpdir and may skip an unusable TMPDIR in favour of another writable candidate such as /tmp.

The attached patch treats a non-empty explicit TMPDIR as the exact parent directory by using File::Temp's DIR option at the actual temporary-root creation call. It preserves the existing system temporary-directory behaviour when TMPDIR is unset or empty.

The patch also adds a regression test for an unwritable explicit TMPDIR, verifies that no /tmp/mmdebstrap.* fallback is selected, and clarifies that this temporary-root path is used for tar, squashfs, ext2, ext4, and null output.

Verification on Ubuntu 24.04 covered unset, empty, writable, unwritable, missing, and non-directory TMPDIR values. Perl syntax, Perl::Critic severity 4, POD rendering, the 79-character code-line limit, and the rendered regression test's ShellCheck and shfmt checks passed.

The complete 283-case source matrix and Debian autopkgtest were not run.

Regards,

Leo (Meng Hsi) Li
GitHub: @teamleaderleo

#1135727#15
Date:
2026-07-30 16:34:36 UTC
From:
To:
Hello,

I reproduced this issue against mmdebstrap 1.5.7-3.

The fallback comes from File::Temp::tempdir(..., TMPDIR => 1), which delegates directory selection to File::Spec->tmpdir and may skip an unusable TMPDIR in favour of another writable candidate such as /tmp.

The attached patch treats a non-empty explicit TMPDIR as the exact parent directory by using File::Temp's DIR option at the actual temporary-root creation call. It preserves the existing system temporary-directory behaviour when TMPDIR is unset or empty.

The patch also adds a regression test for an unwritable explicit TMPDIR, verifies that no /tmp/mmdebstrap.* fallback is selected, and clarifies that this temporary-root path is used for tar, squashfs, ext2, ext4, and null output.

Verification on Ubuntu 24.04 covered unset, empty, writable, unwritable, missing, and non-directory TMPDIR values. Perl syntax, Perl::Critic severity 4, POD rendering, the 79-character code-line limit, and the rendered regression test's ShellCheck and shfmt checks passed.

The complete 283-case source matrix and Debian autopkgtest were not run.

Regards,

Leo (Meng Hsi) Li
GitHub: @teamleaderleo