diff --git a/README.md b/README.md index 5b61659..11e50d0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/GoogleDriveAdapter.php b/src/GoogleDriveAdapter.php index 2d11440..41e5331 100644 --- a/src/GoogleDriveAdapter.php +++ b/src/GoogleDriveAdapter.php @@ -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); @@ -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'))) { @@ -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 ]; } @@ -969,6 +970,7 @@ protected function publish($path) } } } catch (Exception $e) { + // unnecesary } try { $new_permission = new Google_Service_Drive_Permission($this->publishPermission); @@ -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; @@ -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 { @@ -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) { @@ -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) @@ -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; }