378
378
"packages of former installations using "
379
379
"'sudo apt-get clean'.")
381
# gather/log some staticts
381
class FreeSpace(object):
382
" helper class that represents the free space on each mounted fs "
383
def __init__(self, initialFree):
384
self.free = initialFree
387
# it has a map of the dirs we are interessted in and it
388
# contains FreeSpace objects
383
for d in ["/","/usr","/var","/boot"]:
391
archivedir = apt_pkg.Config.FindDir("Dir::Cache::archives")
392
for d in ["/","/usr","/var","/boot", archivedir, "/home"]:
384
393
st = os.statvfs(d)
385
394
free = st[statvfs.F_BAVAIL]*st[statvfs.F_FRSIZE]
386
395
if st in mnt_map:
387
396
logging.debug("Dir %s mounted on %s" % (d,mnt_map[st]))
397
fs_free[d] = fs_free[mnt_map[st]]
389
399
logging.debug("Free space on %s: %s" % (d,free))
401
fs_free[d] = FreeSpace(free)
393
# first check for /var (or where the archives are downloaded too)
394
archivedir = apt_pkg.Config.FindDir("Dir::Cache::archives")
395
st_archivedir = os.statvfs(archivedir)
396
free = st_archivedir[statvfs.F_BAVAIL]*st_archivedir[statvfs.F_FRSIZE]
397
logging.debug("required download: %s " % self.cache.requiredDownload)
398
logging.debug("free on %s: %s " % (archivedir, free))
399
if self.cache.requiredDownload > free:
400
free_at_least = apt_pkg.SizeToStr(self.cache.requiredDownload-free)
401
logging.error("not enough free space (missing %s)" % free_at_least)
402
self._view.error(err_sum, err_long % (free_at_least,archivedir))
405
# then check for /usr assuming that all the data goes into /usr
406
# this won't catch space problems when e.g. /boot,/usr/,/ are all
407
# seperated partitions, but with a fragmented
408
# patition layout we can't do a lot better because we don't know
409
# the space-requirements on a per dir basis inside the deb without
411
logging.debug("need additional space: %s" % self.cache.additionalRequiredSpace)
413
st_usr = os.statvfs(dir)
414
if st_archivedir == st_usr:
415
# we are on the same filesystem, so we need to take the space
416
# for downloading the debs into account
417
free -= self.cache.requiredDownload
418
logging.debug("/usr on same fs as %s, taking dl-size into account, new free: %s" % (archivedir, free))
420
free = st_usr[statvfs.F_BAVAIL]*st_usr[statvfs.F_FRSIZE]
421
logging.debug("/usr on different fs than %s, free: %s" % (archivedir, free))
423
safety_buffer = 1024*1024*100 # 100 Mb
424
logging.debug("using safety buffer: %s" % safety_buffer)
425
if (self.cache.additionalRequiredSpace+safety_buffer) > free:
426
free_at_least = apt_pkg.SizeToStr(self.cache.additionalRequiredSpace+safety_buffer-free)
427
logging.error("not enough free space, we need addional %s" % free_at_least)
428
self._view.error(err_sum, err_long % (free_at_least,dir))
431
# FIXME: we should try to esitmate if "/" has enough free space,
432
# linux-restricted-modules and linux-image- are both putting there
433
# modules there and those take a lot of space
403
logging.debug("fs_free contains: '%s'" % fs_free)
405
# we check for various sizes:
406
# archivedir is were we download the debs
407
# /usr is assumed to get *all* of the install space (incorrect,
408
# but as good as we can do currently + savety buffer
409
# /boot is assumed to get at least 50 Mb
410
# / has a small savety buffer as well
411
for (dir, size) in [(archivedir, self.cache.requiredDownload),
412
("/usr", self.cache.additionalRequiredSpace),
413
("/usr", 50*1024*1024), # savetfy buffer /usr
414
("/boot", 50*1024*1024), # savetfy buffer /boot
415
("/", 10*1024*1024), # small savetfy buffer /
417
logging.debug("dir '%s' needs '%s' of '%s' (%f)" % (dir, size, fs_free[dir], fs_free[dir].free))
418
fs_free[dir].free -= size
419
if fs_free[dir].free < 0:
420
free_at_least = apt_pkg.SizeToStr(abs(fs_free[dir].free)+1)
421
logging.error("not enough free space on %s (missing %s)" % (dir, free_at_least))
422
self._view.error(err_sum, err_long % (free_at_least,dir))