From 31b31a62e1df40150c10b3e70401a1690238a212 Mon Sep 17 00:00:00 2001 From: gvmura Date: Sun, 16 Apr 2017 19:49:55 +0200 Subject: [PATCH] Avoid duplicate files 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: ...") Signed-off-by: gvmura --- apps/files_external/lib/Lib/Storage/Google.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/files_external/lib/Lib/Storage/Google.php b/apps/files_external/lib/Lib/Storage/Google.php index a3133cb4743dc..b8c280b146817 100644 --- a/apps/files_external/lib/Lib/Storage/Google.php +++ b/apps/files_external/lib/Lib/Storage/Google.php @@ -387,6 +387,16 @@ public function unlink($path) { } public function rename($path1, $path2) { + // Avoid duplicate files with the same name + 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);