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

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