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

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