On 11/25/2010 02:02 PM, Denys Vlasenko wrote:
On Thu, 2010-11-25 at 12:09 +0100, Jiri Moskovcak wrote:
A new version with cleaned output. I'd be happy if some can test it and send me some feedback.
def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): package_file_suffix = ".rpm" package_full_path = tmp_dir + "/" + package_nevra + package_file_suffix log1("Extracting %s to %s" % (package_full_path, destdir)) log2(files) print (_("Extracting cpio from %s") % (package_full_path)) unpacked_cpio_out = tmp_dir + "/unpacked.cpio" try: unpacked_cpio = open(unpacked_cpio_out, 'wb') except IOError, ex: print "Can't write to:", (unpacked_cpio_out,ex) return RETURN_FAILURE
This error is not checked where unpack_rpm() is called, in download() function. So it will happily continue. Which is probably wrong: if disk is full, we need to abort.
ok, I made the caller to clean to clean the tmpdir and abort downloading on error
rpm2cpio = Popen(["rpm2cpio", package_full_path], stdout=unpacked_cpio, bufsize=-1) retcode = rpm2cpio.wait() if retcode == 0: log1("cpio written OK") else: unpacked_cpio.close() print (_("Can't extract package: %s") % package_full_path) return RETURN_FAILURE
You probably need to delete $tmp_dir/unpacked.cpio on error. (Unless you change caller to always delete $tmp_dir if unpack_rpm() returns RETURN_FAILURE.
moved unlink(cpio) before the RETURN so, it's removed in case of FAILURE and the directory is then removed by the caller..