diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-02-15 16:49:12 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-02-15 16:49:12 +0100 |
commit | 075dd54f6c4633237e2eef5fe808632c591aef4b (patch) | |
tree | daad52b42e5d245fb5da3528ac37751d5e5ddf3a /apps/files_external | |
parent | 46b39c3465e2db9ba26b23d8d0dfca6cc670aaea (diff) | |
download | nextcloud-server-075dd54f6c4633237e2eef5fe808632c591aef4b.tar.gz nextcloud-server-075dd54f6c4633237e2eef5fe808632c591aef4b.zip |
Fix GDrive handling of office files
1) Properly detect empty file extension, can be null.
2) When renaming part file to final file, use the correct file name
without extension, if it exists
3) When renaming a file, do not delete the original file if it had the
same id, which can happen with part files
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/google.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 8a9ffaf7d37..dd8af6157f7 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -264,7 +264,7 @@ class Google extends \OC\Files\Storage\Common { foreach ($children->getItems() as $child) { $name = $child->getTitle(); // Check if this is a Google Doc i.e. no extension in name - if ($child->getFileExtension() === '' + if (empty($child->getFileExtension()) && $child->getMimeType() !== self::FOLDER ) { $name .= '.'.$this->getGoogleDocExtension($child->getMimeType()); @@ -368,8 +368,14 @@ class Google extends \OC\Files\Storage\Common { public function rename($path1, $path2) { $file = $this->getDriveFile($path1); if ($file) { + $newFile = $this->getDriveFile($path2); if (dirname($path1) === dirname($path2)) { - $file->setTitle(basename(($path2))); + if ($newFile) { + // rename to the name of the target file, could be an office file without extension + $file->setTitle($newFile->getTitle()); + } else { + $file->setTitle(basename(($path2))); + } } else { // Change file parent $parentFolder2 = $this->getDriveFile(dirname($path2)); @@ -394,8 +400,11 @@ class Google extends \OC\Files\Storage\Common { if ($result) { $this->setDriveFile($path1, false); $this->setDriveFile($path2, $result); - if ($oldfile) { - $this->service->files->delete($oldfile->getId()); + if ($oldfile && $newFile) { + // only delete if they have a different id (same id can happen for part files) + if ($newFile->getId() !== $oldfile->getId()) { + $this->service->files->delete($oldfile->getId()); + } } } return (bool)$result; |