From 7fb9bf888950c839c5aa4d00c11256400b075770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= Date: Mon, 18 Feb 2019 13:35:30 +0100 Subject: [PATCH] Truncate single quote in upload file name --- cps/gdriveutils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index cb36a413..9d0e407f 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -323,7 +323,7 @@ def copyToDrive(drive, uploadFile, createRoot, replaceFiles, parent = getEbooksFolder(drive) if os.path.isdir(os.path.join(prevDir,uploadFile)): existingFolder = drive.ListFile({'q': "title = '%s' and '%s' in parents and trashed = false" % - (os.path.basename(uploadFile), parent['id'])}).GetList() + (os.path.basename(uploadFile).replace("'", r"\'"), parent['id'])}).GetList() if len(existingFolder) == 0 and (not isInitial or createRoot): parent = drive.CreateFile({'title': os.path.basename(uploadFile), 'parents': [{"kind": "drive#fileLink", 'id': parent['id']}], @@ -338,11 +338,11 @@ def copyToDrive(drive, uploadFile, createRoot, replaceFiles, else: if os.path.basename(uploadFile) not in ignoreFiles: existingFiles = drive.ListFile({'q': "title = '%s' and '%s' in parents and trashed = false" % - (os.path.basename(uploadFile), parent['id'])}).GetList() + (os.path.basename(uploadFile).replace("'", r"\'"), parent['id'])}).GetList() if len(existingFiles) > 0: driveFile = existingFiles[0] else: - driveFile = drive.CreateFile({'title': os.path.basename(uploadFile), + driveFile = drive.CreateFile({'title': os.path.basename(uploadFile).replace("'", r"\'"), 'parents': [{"kind":"drive#fileLink", 'id': parent['id']}], }) driveFile.SetContentFile(os.path.join(prevDir, uploadFile)) driveFile.Upload()