[Sugar-devel] [PATCH Browse] Cancel a download if space is very tight SL #394

James Cameron quozl at laptop.org
Mon Sep 17 18:40:52 EDT 2012


On Mon, Sep 17, 2012 at 08:24:18AM -0300, Manuel Kaufmann wrote:
> It checks if there will be more than MIN_DISKFREE_AFTER_DOWNLOAD (20Mb)
> after downloading the file. If not, Browse will cancel the download
> process before starting it and an Alert will be shown to the user to
> inform this situation.

...

> @@ -84,8 +91,26 @@ class Download(object):
>          os.close(fd)
>          logging.debug('Download destination path: %s' % self._dest_path)
>  
> -        self._download.set_destination_uri('file://' + self._dest_path)
> -        self._download.start()
> +        # Check free space and if the downloaded file plus an extra
> +        # space will fit on the disk. If not, cancel the download.
> +        total_size = self._download.get_total_size()
> +        logging.debug('Total size of the file: %s', total_size)
> +        if free_space('/') - total_size < MIN_DISKFREE_AFTER_DOWNLOAD:

'/' might not be the filesystem that the download is going to, could
you use the path to the file instead?  That way, if we ever use a
separate filesystem for user files your code won't need another fix.

> +            logging.debug('Download canceled because of Disk Space')
> +            self._canceled_alert = Alert()
> +            self._canceled_alert.props.title = _('Download canceled '
> +                                                  'because of Disk Space')

Cancelled because of what exactly about disk space?  Too much, too
little, wrong colour?  ;-)

I've no other comments about the patch.

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list