[packagekit] How does PK Download Packages?

Richard Hughes hughsient at gmail.com
Sun Jun 22 06:30:38 PDT 2008


On Sun, 2008-06-22 at 12:07 +0200, Tim Lauridsen wrote:
> The attach file should contain the need code to download a list of yum 
> packages to at specified destdir.
> All you need to do, is use the _find_package to find yum package objects 
> for the package_ids and call the attacted code.

Legend, thanks.

> def _download_packages(self,toDownload,destdir):

toDownload wants to be called package_ids

>     ''' 
>     download the yum packages contained in the 
>     to doDownload list to the 'destdir' directory
>     '''
>     for pkg in toDownload:
>         n,a,e,v,r = pkg.pkgtup
>         packages =  self.pkgSack.searchNevra(n,e,v,r,a)
>         for download in packages:
>             repo = self.repos.getRepo(download.repoid)
>             remote = download.returnSimple('relativepath')
>             local = os.path.basename(remote)
>             if not os.path.exists(destdir):
>                 os.makedirs(destdir)

Don't makedirs this - else we can trick the script (running as root) to
create directories in bad places == security hole.

>             local = os.path.join(destdir, local)
>             if (os.path.exists(local) and 
>                 os.path.getsize(local) ==
> int(download.returnSimple('packagesize'))):
>                 print "%s already exists and appears to be complete" %
> local
>                 continue
>             # Disable cache otherwise things won't download
>             repo.cache = 0
>             download.localpath = local # Hack: to set the localpath we
> want.
>             try:
>                 path = repo.getPackage(download)
>             except IOError, e:
>                 print "Cannot write to file %s. Error was: %s" % 

You need to use ErrorCode to report to the user.

Shishir, can you make these changes for me please. Thanks!

Richard.





More information about the PackageKit mailing list