Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jun 25, 2021
2 parents 0b1a866 + ea7629e commit b15f06f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![Latest Version on Packagist](https://img.shields.io/packagist/v/masbug/flysystem-google-drive-ext.svg?style=flat-square)](https://packagist.org/packages/masbug/flysystem-google-drive-ext)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build Status](https://img.shields.io/travis/masbug/flysystem-google-drive-ext/master.svg?style=flat-square)](https://travis-ci.org/masbug/flysystem-google-drive-ext)
[![StyleCI](https://styleci.io/repos/113434522/shield?branch=master)](https://styleci.io/repos/113434522)
[![Build Status](https://img.shields.io/travis/masbug/flysystem-google-drive-ext/2.x.svg?style=flat-square)](https://travis-ci.org/masbug/flysystem-google-drive-ext)
[![StyleCI](https://styleci.io/repos/113434522/shield?branch=2.x)](https://styleci.io/repos/113434522)
[![Total Downloads](https://img.shields.io/packagist/dt/masbug/flysystem-google-drive-ext.svg?style=flat-square)](https://packagist.org/packages/masbug/flysystem-google-drive-ext)

Google uses unique IDs for each folder and file. This makes it difficult to integrate with other storage services which use normal paths.
Expand Down
23 changes: 17 additions & 6 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ public function copy(string $location, string $destination, Config $config): voi
}
}
} catch (Exception $e) {
// unnecesary
}
if ($config->get('visibility') === Visibility::PUBLIC || $visibility === Visibility::PUBLIC) {
$this->publish($id);
Expand Down Expand Up @@ -489,7 +490,7 @@ protected function delete_by_id($ids)
}
foreach ($ids as $id) {
if ($id !== '' && ($file = $this->getFileObject($id))) {
if (($parents = $file->getParents())) {
if ($file->getParents()) {
$file = new Google_Service_Drive_DriveFile();
$file->setTrashed(true);
if ($this->service->files->update($id, $file, $this->applyDefaultParams([], 'files.update'))) {
Expand Down Expand Up @@ -906,7 +907,7 @@ public function getUrl($path)
public function hasDir($path)
{
$meta = $this->getMetadata($path)->extraMetadata();
return ($meta && isset($meta['hasdir'])) ? $meta : [
return (is_array($meta) && isset($meta['hasdir'])) ? $meta : [
'hasdir' => true
];
}
Expand Down Expand Up @@ -969,6 +970,7 @@ protected function publish($path)
}
}
} catch (Exception $e) {
// unnecesary
}
try {
$new_permission = new Google_Service_Drive_Permission($this->publishPermission);
Expand Down Expand Up @@ -1081,6 +1083,7 @@ protected function normaliseObject(Google_Service_Drive_DriveFile $object, $dirn
}
}
} catch (Exception $e) {
// unnecesary
}
if ($this->useDisplayPaths) {
$result['virtual_path'] = ($dirname ? ($dirname.'/') : '').$id;
Expand Down Expand Up @@ -1214,7 +1217,7 @@ public function getFileObject($path, $checkDir = false)

$batch->add($request, 'hasdir');
}
$results = array_values($batch->execute());
$results = array_values($batch->execute() ?: []);

[$fileObj, $hasdir] = array_pad($results, 2, null);
} finally {
Expand Down Expand Up @@ -1297,7 +1300,7 @@ protected function createDir($name, $parentId)
* @param string|resource $contents
* @param Config $config
* @param bool|null $updating If null then we check for existence of the file
* @return array|false item info array
* @return \League\Flysystem\StorageAttributes|false item info
*/
protected function upload($path, $contents, Config $config, $updating = null)
{
Expand Down Expand Up @@ -1841,7 +1844,7 @@ protected function returnSingle($item, $returnFirstItem)
* @param string $displayPath
* @param bool $makeFullVirtualPath
* @param bool $returnFirstItem
* @return string[]|string Single itemId/path or array of them
* @return string Single itemId/path
* @throws FileNotFoundException
*/
protected function toVirtualPath($displayPath, $makeFullVirtualPath = true, $returnFirstItem = false)
Expand Down Expand Up @@ -1924,7 +1927,15 @@ protected function toSingleVirtualPath($displayPath, $makeFullVirtualPath = true
}

$subdir = $is_dir ? $displayPath : self::dirname($displayPath);
if ($subdir === '' || !is_null($this->createDirectory($subdir, new Config()))) {
if ($subdir === '') {
if ($can_throw) {
throw $e;
}
return false;
}

$this->createDirectory($subdir, new Config());
if(!$this->hasDir($subdir)){
if ($can_throw) {
throw $e;
}
Expand Down

0 comments on commit b15f06f

Please sign in to comment.