Merge pull request #25007 from owncloud/gdrive-fixuploadsamenameasfolder
Fix GDrive upload file which name might match the one of a folder
This commit is contained in:
commit
4fd55c255f
|
@ -97,6 +97,9 @@ class Google extends \OC\Files\Storage\Common {
|
||||||
private function getDriveFile($path) {
|
private function getDriveFile($path) {
|
||||||
// Remove leading and trailing slashes
|
// Remove leading and trailing slashes
|
||||||
$path = trim($path, '/');
|
$path = trim($path, '/');
|
||||||
|
if ($path === '.') {
|
||||||
|
$path = '';
|
||||||
|
}
|
||||||
if (isset($this->driveFiles[$path])) {
|
if (isset($this->driveFiles[$path])) {
|
||||||
return $this->driveFiles[$path];
|
return $this->driveFiles[$path];
|
||||||
} else if ($path === '') {
|
} else if ($path === '') {
|
||||||
|
@ -138,7 +141,7 @@ class Google extends \OC\Files\Storage\Common {
|
||||||
if ($pos !== false) {
|
if ($pos !== false) {
|
||||||
$pathWithoutExt = substr($path, 0, $pos);
|
$pathWithoutExt = substr($path, 0, $pos);
|
||||||
$file = $this->getDriveFile($pathWithoutExt);
|
$file = $this->getDriveFile($pathWithoutExt);
|
||||||
if ($file) {
|
if ($file && $this->isGoogleDocFile($file)) {
|
||||||
// Switch cached Google_Service_Drive_DriveFile to the correct index
|
// Switch cached Google_Service_Drive_DriveFile to the correct index
|
||||||
unset($this->driveFiles[$pathWithoutExt]);
|
unset($this->driveFiles[$pathWithoutExt]);
|
||||||
$this->driveFiles[$path] = $file;
|
$this->driveFiles[$path] = $file;
|
||||||
|
@ -208,6 +211,17 @@ class Google extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the given drive file is a Google Doc file
|
||||||
|
*
|
||||||
|
* @param \Google_Service_Drive_DriveFile
|
||||||
|
*
|
||||||
|
* @return true if the file is a Google Doc file, false otherwise
|
||||||
|
*/
|
||||||
|
private function isGoogleDocFile($file) {
|
||||||
|
return $this->getGoogleDocExtension($file->getMimeType()) !== '';
|
||||||
|
}
|
||||||
|
|
||||||
public function mkdir($path) {
|
public function mkdir($path) {
|
||||||
if (!$this->is_dir($path)) {
|
if (!$this->is_dir($path)) {
|
||||||
$parentFolder = $this->getDriveFile(dirname($path));
|
$parentFolder = $this->getDriveFile(dirname($path));
|
||||||
|
|
|
@ -60,4 +60,13 @@ class GoogleTest extends \Test\Files\Storage\Storage {
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSameNameAsFolderWithExtension() {
|
||||||
|
$this->assertTrue($this->instance->mkdir('testsamename'));
|
||||||
|
$this->assertEquals(13, $this->instance->file_put_contents('testsamename.txt', 'some contents'));
|
||||||
|
$this->assertEquals('some contents', $this->instance->file_get_contents('testsamename.txt'));
|
||||||
|
$this->assertTrue($this->instance->is_dir('testsamename'));
|
||||||
|
$this->assertTrue($this->instance->unlink('testsamename.txt'));
|
||||||
|
$this->assertTrue($this->instance->rmdir('testsamename'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue