From ba106578297098b9517af44e31558e25c1e82f98 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 28 Jun 2020 12:06:27 +0200 Subject: [PATCH] Add fix for read only gdrive file --- cps/gdriveutils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 987a8405..9ea0479d 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -27,6 +27,7 @@ from sqlalchemy import Column, UniqueConstraint from sqlalchemy import String, Integer from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.exc import OperationalError, InvalidRequestError try: from pydrive.auth import GoogleAuth @@ -479,8 +480,13 @@ def getChangeById (drive, change_id): # Deletes the local hashes database to force search for new folder names def deleteDatabaseOnChange(): - session.query(GdriveId).delete() - session.commit() + try: + session.query(GdriveId).delete() + session.commit() + except (OperationalError, InvalidRequestError): + session.rollback() + log.info(u"GDrive DB is not Writeable") + def updateGdriveCalibreFromLocal(): copyToDrive(Gdrive.Instance().drive, config.config_calibre_dir, False, True)