Kaydet (Commit) 7303df78 authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

Added new feature: Now control free space before installing package

üst 5915e696
......@@ -136,6 +136,7 @@ class Install(AtomicOperation):
self.metadata = self.package.metadata
self.files = self.package.files
self.pkginfo = self.metadata.package
self.installedSize = self.metadata.package.installedSize
self.installdb = inary.db.installdb.InstallDB()
self.operation = INSTALL
self.store_old_paths = None
......@@ -173,7 +174,11 @@ class Install(AtomicOperation):
def check_requirements(self):
"""check system requirements"""
#TODO: IS THERE ENOUGH SPACE?
# Check free space
ctx.ui.debug(_("Free Space: {} MB").format(util.free_space() / (1024*1024.0)))
if util.free_space() < self.installedSize:
raise Error(_("Is there any free space in your disk."))
# what to do if / is split into /usr, /var, etc.
# check scom
if self.metadata.package.providesScom and ctx.scom:
......
......@@ -118,6 +118,7 @@ class MetaData(xmlfile.XmlFile, metaclass=autoxml.autoxml):
self.package.history = history
self.package.conflicts = pkg.conflicts
self.package.replaces = pkg.replaces
self.package.installedSize = pkg.installledsize
self.package.additionalFiles = pkg.additionalFiles
# FIXME: right way to do it?
......
......@@ -361,6 +361,16 @@ def copy_file_stat(src,dest):
ensure_dirs(os.path.dirname(dest))
shutil.copy2(src, dest)
def free_space(directory=None):
"""Returns the free space (x Byte) in the device. """
if not directory:
# Defaults to /
directory = ctx.config.values.general.destinationdirectory
_stat = os.statvfs(directory)
free_space = _stat.f_bfree * _stat.f_bsize
return free_space
def read_link(link):
"""Return the normalized path which is pointed by the symbolic link."""
# tarfile module normalizes the paths pointed by symbolic links. This
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment