summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>2025-09-17 22:58:17 +0200
committerJulian Andres Klode <jak@debian.org>2026-01-05 22:28:03 +0100
commit68968d8af49500c949d679de184a2201d9e56cbe (patch)
tree47461aa7a0005dad23af26285160bf5ac3a22001
parentfdbcc2e297ed6e097b30298996710a4c0ec7fbd6 (diff)
apt-private/private-download.cc: support unlimited space tmpfs
Test like this: sudo mount -t tmpfs -o size=0 tmpfs rootfs cat << 'END' > run.sh set -exu export LD_LIBRARY_PATH=/home/josch/git/apt/build/apt-pkg mkdir -p "$1/etc/apt" "$1/var/cache" "$1/var/lib/dpkg/" echo "Dir \"$(cd "$1" && pwd)\";" > "$1/apt.conf" echo "deb [signed-by=/usr/share/keyrings/debian-archive-keyring.pgp] http://deb.debian.org/debian/ unstable main" > "$1/etc/apt/sources.list" APT_CONFIG="$1/apt.conf" build/cmdline/apt-get update APT_CONFIG="$1/apt.conf" build/cmdline/apt-get --yes --download-only install '?essential' END ./run.sh rootfs
-rw-r--r--apt-private/private-download.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc
index e3d425283..60cdfc9ec 100644
--- a/apt-private/private-download.cc
+++ b/apt-private/private-download.cc
@@ -127,6 +127,7 @@ bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failu
bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long FetchBytes)/*{{{*/
{
uint32_t const RAMFS_MAGIC = 0x858458f6;
+ uint32_t const TMPFS_MAGIC = 0x01021994;
/* Check for enough free space, but only if we are actually going to
download */
if (_config->FindB("APT::Get::Print-URIs", false) == true ||
@@ -142,22 +143,21 @@ bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long Fet
return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
Dir.c_str());
}
- else
- {
- unsigned long long const FreeBlocks = _config->Find("APT::Sandbox::User").empty() ? Buf.f_bfree : Buf.f_bavail;
- if (FreeBlocks < (FetchBytes / Buf.f_bsize))
- {
- struct statfs Stat;
- if (statfs(Dir.c_str(),&Stat) != 0
+ unsigned long long const FreeBlocks = _config->Find("APT::Sandbox::User").empty() ? Buf.f_bfree : Buf.f_bavail;
+ if (FreeBlocks >= (FetchBytes / Buf.f_bsize))
+ return true;
+ struct statfs Stat;
+ if (statfs(Dir.c_str(), &Stat) != 0)
+ return _error->Error(_("Couldn't determine filesystem statistics of %s."), Dir.c_str());
+
#ifdef HAVE_STRUCT_STATFS_F_TYPE
- || Stat.f_type != RAMFS_MAGIC
+ if (Stat.f_type == RAMFS_MAGIC)
+ return true;
+ // do not run out of space on a tmpfs without a size limit (size is zero)
+ if (Stat.f_type == TMPFS_MAGIC && Buf.f_blocks == 0)
+ return true;
#endif
- )
- return _error->Error(_("You don't have enough free space in %s."),
- Dir.c_str());
- }
- }
- return true;
+ return _error->Error(_("You don't have enough free space in %s."), Dir.c_str());
}
/*}}}*/