From 888dfdffaf4f8829466e4c09ede356071cc17970 Mon Sep 17 00:00:00 2001 From: gvmura Date: Fri, 21 Apr 2017 09:53:52 +0200 Subject: [PATCH 1/2] avoid duplicate files in google with the same name When it renames the temporary file, it tests if the file is already present. If so, it moves to trash the previous version to avoid duplicate files with the same name (message log: "Ignoring duplicate file name: ... on Google Drive for Google user: ..."). It doesn't handle duplicate files in Google Drive, it tries to avoid them. You'll watch #4279 issue. --- apps/files_external/lib/Lib/Storage/Google.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/files_external/lib/Lib/Storage/Google.php b/apps/files_external/lib/Lib/Storage/Google.php index 2211686055eab..0a88ccc8d42ac 100644 --- a/apps/files_external/lib/Lib/Storage/Google.php +++ b/apps/files_external/lib/Lib/Storage/Google.php @@ -386,6 +386,19 @@ public function unlink($path) { } public function rename($path1, $path2) { + // Avoid duplicate files with the same name + $testRegex = '/^.+\.ocTransferId\d+\.part$/'; + if (preg_match($testRegex, $path1)) { + if ($this->is_file($path2)) { + $testFile2 = $this->getDriveFile($path2); + if ($testFile2) { + $this->service->files->trash($testFile2->getId()); + \OCP\Util::writeLog('files_external', 'trash file '.$path2. + ' for renaming '.$path1.' on Google Drive.', \OCP\Util::DEBUG); + } + } + } + $file = $this->getDriveFile($path1); if ($file) { $newFile = $this->getDriveFile($path2); From 0d063c316a18ce8a8c77948dcc6a6ae32452d758 Mon Sep 17 00:00:00 2001 From: gvmura Date: Fri, 21 Apr 2017 09:53:52 +0200 Subject: [PATCH 2/2] avoid duplicate files in google with the same name Signed-off-by: gvmura --- apps/files_external/lib/Lib/Storage/Google.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/files_external/lib/Lib/Storage/Google.php b/apps/files_external/lib/Lib/Storage/Google.php index 2211686055eab..0a88ccc8d42ac 100644 --- a/apps/files_external/lib/Lib/Storage/Google.php +++ b/apps/files_external/lib/Lib/Storage/Google.php @@ -386,6 +386,19 @@ public function unlink($path) { } public function rename($path1, $path2) { + // Avoid duplicate files with the same name + $testRegex = '/^.+\.ocTransferId\d+\.part$/'; + if (preg_match($testRegex, $path1)) { + if ($this->is_file($path2)) { + $testFile2 = $this->getDriveFile($path2); + if ($testFile2) { + $this->service->files->trash($testFile2->getId()); + \OCP\Util::writeLog('files_external', 'trash file '.$path2. + ' for renaming '.$path1.' on Google Drive.', \OCP\Util::DEBUG); + } + } + } + $file = $this->getDriveFile($path1); if ($file) { $newFile = $this->getDriveFile($path2);