movefile: simplify xattr fallback logic
authorMike Frysinger <vapier@gentoo.org>
Wed, 16 Oct 2013 18:41:02 +0000 (14:41 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 16 Oct 2013 20:33:01 +0000 (16:33 -0400)
The "with open()" construct handles exceptions just fine.

pym/portage/util/movefile.py

index 65d81c6bb302e3c52aba1aef9ac3948d5894f0d8..4f158cd00a08e3b8d1f93c915b0e58d8adc886cb 100644 (file)
@@ -128,15 +128,11 @@ else:
                                                "does not support extended attribute '%s'") %
                                                (_unicode_decode(dest), _unicode_decode(attr)))
        else:
-               _devnull = open("/dev/null", "wb")
                try:
-                       subprocess.call(["getfattr", "--version"], stdout=_devnull)
-                       subprocess.call(["setfattr", "--version"], stdout=_devnull)
-                       _has_getfattr_and_setfattr = True
+                       with open(os.devnull, 'wb') as f:
+                               subprocess.call(["getfattr", "--version"], stdout=f)
+                               subprocess.call(["setfattr", "--version"], stdout=f)
                except OSError:
-                       _has_getfattr_and_setfattr = False
-               _devnull.close()
-               if _has_getfattr_and_setfattr:
                        def _copyxattr(src, dest, exclude=None):
                                # TODO: implement exclude
                                getfattr_process = subprocess.Popen(["getfattr", "-d", "--absolute-names", src], stdout=subprocess.PIPE)