Blame SOURCES/BZ-1493489-yum-config-manager-fix-add-repo-2.patch

b7ec20
diff -up yum-utils-1.1.31/yum-config-manager.py.orig yum-utils-1.1.31/yum-config-manager.py
b7ec20
--- yum-utils-1.1.31/yum-config-manager.py.orig	2018-08-17 20:19:31.581457215 +0200
b7ec20
+++ yum-utils-1.1.31/yum-config-manager.py	2018-08-17 20:19:34.077487757 +0200
b7ec20
@@ -8,6 +8,8 @@ sys.path.insert(0,'/usr/share/yum-cli')
b7ec20
 from utils import YumUtilBase
b7ec20
 import logging
b7ec20
 import fnmatch
b7ec20
+import tempfile
b7ec20
+import shutil
b7ec20
 
b7ec20
 from iniparse import INIConfig
b7ec20
 import yum.config
b7ec20
@@ -215,6 +217,7 @@ if opts.addrepo:
b7ec20
         myrepodir = yb.conf.reposdir[0]
b7ec20
         os.makedirs(myrepodir)
b7ec20
         
b7ec20
+    error = False
b7ec20
     for url in opts.addrepo:
b7ec20
         print 'adding repo from: %s' % url
b7ec20
         if url.endswith('.repo'): # this is a .repo file - fetch it, put it in our reposdir and enable it
b7ec20
@@ -223,18 +226,24 @@ if opts.addrepo:
b7ec20
 
b7ec20
             # dummy grabfunc, using [main] options
b7ec20
             repo = yum.yumRepo.YumRepository('dummy')
b7ec20
-            repo.baseurl = ['http://dummy']
b7ec20
+            repo.baseurl = ['http://dummy/']
b7ec20
             repo.populate(yum.config.ConfigParser(), None, yb.conf)
b7ec20
             grabber = repo.grabfunc; del repo
b7ec20
 
b7ec20
             print 'grabbing file %s to %s' % (url, destname)
b7ec20
+            f = tempfile.NamedTemporaryFile()
b7ec20
             try:
b7ec20
-                result  = grabber.urlgrab(url, filename=destname, copy_local=True, reget=None)
b7ec20
+                grabber.urlgrab(url, filename=f.name, copy_local=True, reget=None)
b7ec20
+                shutil.copy2(f.name, destname)
b7ec20
+                os.chmod(destname, 0o644)
b7ec20
             except (IOError, OSError, yum.Errors.YumBaseError), e:
b7ec20
                 logger.error('Could not fetch/save url %s to file %s: %s'  % (url, destname, e))
b7ec20
+                error = True
b7ec20
                 continue
b7ec20
             else:
b7ec20
-                print 'repo saved to %s' % result
b7ec20
+                print 'repo saved to %s' % destname
b7ec20
+            finally:
b7ec20
+                f.close()
b7ec20
             
b7ec20
         else:
b7ec20
             repoid = sanitize_url_to_fs(url)
b7ec20
@@ -244,7 +253,16 @@ if opts.addrepo:
b7ec20
                 thisrepo = yb.add_enable_repo(repoid, baseurl=[url], name=reponame)
b7ec20
             except yum.Errors.DuplicateRepoError, e:
b7ec20
                 logger.error('Cannot add repo from %s as is a duplicate of an existing repo' % url)
b7ec20
+                error = True
b7ec20
                 continue
b7ec20
+
b7ec20
+            try:
b7ec20
+                yum.config.UrlOption().parse(url)
b7ec20
+            except ValueError, e:
b7ec20
+                logger.error('Cannot add repo from %s: %s' % (url, e))
b7ec20
+                error = True
b7ec20
+                continue
b7ec20
+
b7ec20
             repoout = """\n[%s]\nname=%s\nbaseurl=%s\nenabled=1\n\n""" % (repoid, reponame, url)
b7ec20
 
b7ec20
             try:
b7ec20
@@ -253,9 +271,10 @@ if opts.addrepo:
b7ec20
                 print repoout
b7ec20
             except (IOError, OSError), e:
b7ec20
                 logger.error('Could not save repo to repofile %s: %s' % (repofile, e))
b7ec20
+                error = True
b7ec20
                 continue
b7ec20
             else:
b7ec20
                 fo.close()
b7ec20
-                
b7ec20
-            
b7ec20
 
b7ec20
+    if error:
b7ec20
+        sys.exit(1)