Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x]Fix README.md #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -335,7 +335,7 @@ private function writeData(string $location, $contents, Config $config)
$path = $this->prefixer->prefixPath($location);
if ($this->useDisplayPaths) {
try {
$virtual_path = $this->toVirtualPath($path, true, false);
$virtual_path = $this->toVirtualPath($path, true, true);
$updating = true; // destination exists
} catch (UnableToReadFile $e) {
$updating = false;
Expand Down 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 @@ -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