diff options
-rwxr-xr-x | git-bz | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -525,7 +525,7 @@ class BugHandle: class CookieError(Exception): pass -def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_time): +def do_get_cookies_from_sqlite(params, cookies_sqlite, browser, query, chromium_time): result = {} # We use a timeout of 0 since we expect to hit the browser holding # the lock often and we need to fall back to making a copy without a delay @@ -533,7 +533,7 @@ def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_ti try: cursor = connection.cursor() - cursor.execute(query, { 'host': host }) + cursor.execute(query, params) now = time.time() for name,value,path,expiry in cursor.fetchall(): @@ -556,24 +556,26 @@ def do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_ti # Firefox 3.5 keeps the cookies database permamently locked; as a workaround # hack, we make a copy, read from that, then delete the copy. Of course, # we may hit an inconsistent state of the database -def get_cookies_from_sqlite_with_copy(host, cookies_sqlite, browser, *args, **kwargs): +def get_cookies_from_sqlite_with_copy(params, cookies_sqlite, browser, *args, **kwargs): db_copy = cookies_sqlite + ".git-bz-temp" shutil.copyfile(cookies_sqlite, db_copy) try: - return do_get_cookies_from_sqlite(host, db_copy, browser, *args, **kwargs) + return do_get_cookies_from_sqlite(params, db_copy, browser, *args, **kwargs) except sqlite.OperationalError, e: raise CookieError("Cookie database was locked; temporary copy didn't work") finally: os.remove(db_copy) -def get_cookies_from_sqlite(host, cookies_sqlite, browser, query, chromium_time=False): +def get_cookies_from_sqlite(host, cookies_sqlite, browser, query, params=None, chromium_time=False): + if not params: + params = { 'host': host } try: - result = do_get_cookies_from_sqlite(host, cookies_sqlite, browser, query, + result = do_get_cookies_from_sqlite(params, cookies_sqlite, browser, query, chromium_time=chromium_time) except sqlite.OperationalError, e: if "database is locked" in str(e): # Try making a temporary copy - result = get_cookies_from_sqlite_with_copy(host, cookies_sqlite, browser, query, + result = get_cookies_from_sqlite_with_copy(params, cookies_sqlite, browser, query, chromium_time=chromium_time) else: raise @@ -643,8 +645,8 @@ def get_bugzilla_cookies_chr(host, browser, config_dir): if not os.path.exists(cookies_sqlite): raise CookieError("%s doesn't exist" % cookies_sqlite) return get_cookies_from_sqlite(host, cookies_sqlite, browser, - "select name,value,path,expires_utc from cookies where host_key = :host", - chromium_time=True) + "select name,value,path,expires_utc from cookies where host_key = :host or host_key = :dothost", + params={ "host": host, "dothost": ".%s" % host }, chromium_time=True) def get_bugzilla_cookies_chromium(host): return get_bugzilla_cookies_chr(host, |