Error handling when removing profiles.
authorMark Cote <mcote@mozilla.com>
Fri, 30 Mar 2012 12:25:52 -0400
changeset 87 8a3ed8ba8f12da19be7711fc808e8d7a4c5637dd
parent 86 0644c041e21768bf3c9db93839b20a7426df054e
child 88 66bec4f39c9781db1e94c126b6a7b6d9c790c512
push id85
push usermcote@mozilla.com
push dateFri, 30 Mar 2012 16:26:01 +0000
Error handling when removing profiles.
client/speedtests.py
--- a/client/speedtests.py
+++ b/client/speedtests.py
@@ -189,17 +189,31 @@ class BrowserController(object):
         if not self.browser_exists():
             return False
         for p in self.profiles:
             profile_archive = self.get_profile_archive_path(p)
             if not os.path.exists(profile_archive):
                 print 'Warning: no archived profile'
                 return True
             if os.path.exists(p['path']):
-                shutil.rmtree(p['path'])
+                attempts = 0
+                while attempts < 3:
+                    if attempts > 0:
+                        time.sleep(5)
+                    try:
+                        shutil.rmtree(p['path'])
+                    except (OSError, WindowsError):
+                        print 'Failed to remove profile:'
+                        traceback.print_exc()
+                        attempts += 1
+                    else:
+                        break
+                if attempts == 3:
+                    print 'Couldn\'t remove profile; giving up.'
+                    return False
             try:
                 os.mkdir(p['path'])
             except OSError:
                 pass
             profile_zip = zipfile.ZipFile(profile_archive, 'r')
             print 'Copying profile to %s...' % p['path']
             profile_zip.extractall(p['path'])
         return True