Skip to content

Commit

Permalink
Fix GDrive handling of office files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Vincent Petry committed Feb 15, 2016
1 parent 46b39c3 commit 075dd54
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/files_external/lib/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function opendir($path) {
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());
Expand Down Expand Up @@ -368,8 +368,14 @@ public function unlink($path) {
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));
Expand All @@ -394,8 +400,11 @@ public function rename($path1, $path2) {
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;
Expand Down

0 comments on commit 075dd54

Please sign in to comment.