diff --git a/src/Disk/Adapter/AdapterFilesystem.php b/src/Disk/Adapter/AdapterFilesystem.php index 496b5e4..09e1f9a 100644 --- a/src/Disk/Adapter/AdapterFilesystem.php +++ b/src/Disk/Adapter/AdapterFilesystem.php @@ -92,11 +92,16 @@ public function directoryExists(string $path): bool */ public function write(string $path, string $contents, $config = []) { - $this->adapter->write($path, $contents, new Config($config)); + try { + $this->adapter->write($path, $contents, new Config($config)); - $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); + $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); + + return dispatch_sync(new SyncFile($entry, $this->disk)); - return dispatch_sync(new SyncFile($entry, $this->disk)); + } catch (FilesystemException $exception) { + return false; + } } /** @@ -108,11 +113,16 @@ public function write(string $path, string $contents, $config = []) */ public function writeStream(string $path, $contents, $config = []) { - $this->adapter->writeStream($path, $contents, new Config($config)); + try { + $this->adapter->writeStream($path, $contents, new Config($config)); + + $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); - $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); + return dispatch_sync(new SyncFile($entry, $this->disk)); - return dispatch_sync(new SyncFile($entry, $this->disk)); + } catch (FilesystemException $exception) { + return false; + } } /** @@ -252,11 +262,18 @@ private function listDirectory(string $location) */ public function delete(string $path) { - $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); + try { + $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); - $this->adapter->delete($path); + $this->adapter->delete($path); - dispatch_sync(new DeleteFile($entry)); + dispatch_sync(new DeleteFile($entry)); + + return true; + + } catch (FilesystemException $exception) { + return false; + } } @@ -267,9 +284,16 @@ public function delete(string $path) */ public function deleteDirectory(string $path) { - $this->adapter->deleteDirectory($path); + try { + $this->adapter->deleteDirectory($path); - return dispatch_sync(new DeleteFolder($path)); + dispatch_sync(new DeleteFolder($path)); + + return true; + + } catch (FilesystemException $exception) { + return false; + } } /** @@ -280,9 +304,14 @@ public function deleteDirectory(string $path) */ public function createDirectory(string $path, $config = []) { - $this->adapter->createDirectory($path, new Config($config)); + try { + $this->adapter->createDirectory($path, new Config($config)); - return dispatch_sync(new SyncFolder($path, $this->disk)); + return dispatch_sync(new SyncFolder($path, $this->disk)); + + } catch (FilesystemException $exception) { + return false; + } } /** @@ -293,7 +322,12 @@ public function createDirectory(string $path, $config = []) */ public function move(string $source, string $destination, $config = []) { - $this->adapter->move($source, $destination, new Config($config)); + try { + $this->adapter->move($source, $destination, new Config($config)); + return true; + } catch (FilesystemException $exception) { + return false; + } } /** @@ -305,13 +339,17 @@ public function move(string $source, string $destination, $config = []) */ public function copy(string $source, string $destination, $config = []) { - $this->adapter->copy($source, $destination, new Config($config)); - - if (is_dir($source)) { - return dispatch_sync(new SyncFolder($path, $this->disk)); - } else { - $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); - return dispatch_sync(new SyncFile($entry, $this->disk)); + try { + $this->adapter->copy($source, $destination, new Config($config)); + + if (is_dir($source)) { + return dispatch_sync(new SyncFolder($path, $this->disk)); + } else { + $entry = new FileAttributes($path, $this->fileSize($path), null, null, $this->mimeType($path)); + return dispatch_sync(new SyncFile($entry, $this->disk)); + } + } catch (FilesystemException $exception) { + return false; } } @@ -358,4 +396,4 @@ public function getDisk() { return $this->disk; } -} \ No newline at end of file +} diff --git a/src/Disk/Adapter/Command/DeleteFile.php b/src/Disk/Adapter/Command/DeleteFile.php index b2fe84f..5db3ba3 100644 --- a/src/Disk/Adapter/Command/DeleteFile.php +++ b/src/Disk/Adapter/Command/DeleteFile.php @@ -41,7 +41,7 @@ public function handle(FileRepositoryInterface $files, FolderRepositoryInterface { $folder = $folders->findBySlug(dirname($this->file->path())); if ($file = $files->findByNameAndFolder(basename($this->file->path()), $folder)) { - return $files->delete($file); + return $files->forceDelete($file); } } } diff --git a/src/File/Command/SetDimensions.php b/src/File/Command/SetDimensions.php index 5354833..9d1cdd0 100644 --- a/src/File/Command/SetDimensions.php +++ b/src/File/Command/SetDimensions.php @@ -39,9 +39,9 @@ public function handle() if (!in_array($this->file->getExtension(), ['jpg', 'jpeg', 'png'])) { return; } - + try { - list($width, $height) = getimagesize($this->file->path()); + list($width, $height) = getimagesize(app('filesystem')->disk($this->file->getDiskSlug())->url($this->file->path())); } catch (\Exception $e) { return; } diff --git a/src/File/FileDownloader.php b/src/File/FileDownloader.php index 7f365c4..2ece3b2 100644 --- a/src/File/FileDownloader.php +++ b/src/File/FileDownloader.php @@ -42,7 +42,7 @@ public function make(FileInterface $file) $disk = $folder->getDisk(); return $response->setContent( - $this->manager->read("{$disk->getSlug()}://{$folder->getSlug()}/{$file->getName()}") + $this->manager->disk($file->getDiskSlug())->read("{$folder->getSlug()}/{$file->getName()}") ); } } diff --git a/src/File/FileImage.php b/src/File/FileImage.php index 52535eb..dfc0276 100644 --- a/src/File/FileImage.php +++ b/src/File/FileImage.php @@ -1,8 +1,8 @@ image = $image; diff --git a/src/File/FileManager.php b/src/File/FileManager.php index e93e63c..098a2df 100644 --- a/src/File/FileManager.php +++ b/src/File/FileManager.php @@ -1,7 +1,7 @@ manager = $manager; } @@ -37,13 +37,17 @@ public function __construct(MountManager $manager) */ public function move($from, $to) { - $result = $this->manager->put($to, $contents = $this->manager->read($from), ['sync' => false]); + list($from_disk, $from_path) = explode('://', $from, 2); + list($to_disk, $to_path) = explode('://', $to, 2); - if ($result && $this->manager->has($to)) { + $stream = $this->manager->disk($from_disk)->readStream($from_path); + $result = $this->manager->disk($to_disk)->writeStream($to_path, $stream); + + if ($result && $this->manager->disk($to_disk)->fileExists($to_path)) { $result = dispatch_sync(new MoveFile($from, $to)); } - $this->manager->delete($from); + $this->manager->disk($from_disk)->delete($from_path); return $result; } diff --git a/src/File/FileModel.php b/src/File/FileModel.php index cc5a67e..8a16785 100644 --- a/src/File/FileModel.php +++ b/src/File/FileModel.php @@ -1,10 +1,7 @@ getFilesystem($this->getDiskSlug()); + return app('filesystem')->disk($this->getDiskSlug()); } /** * Return the file resource. * Return the file resource. * - * @return null|File + * @return null */ public function resource() { diff --git a/src/File/FileReader.php b/src/File/FileReader.php index 0c95f29..1eb76ab 100644 --- a/src/File/FileReader.php +++ b/src/File/FileReader.php @@ -38,6 +38,6 @@ public function make(FileInterface $file) $response->headers->set('Content-Disposition', 'inline'); - return $response->setContent($this->manager->read($file->location())); + return $response->setContent($this->manager->disk($file->getDiskSlug())->read($file->path())); } } diff --git a/src/File/FileResponse.php b/src/File/FileResponse.php index b729efe..3f67ac4 100644 --- a/src/File/FileResponse.php +++ b/src/File/FileResponse.php @@ -1,9 +1,9 @@ manager = $manager; $this->response = $response; diff --git a/src/File/FileStreamer.php b/src/File/FileStreamer.php index 4ae3c0f..7969f5e 100644 --- a/src/File/FileStreamer.php +++ b/src/File/FileStreamer.php @@ -1,9 +1,9 @@ request = $request; @@ -49,8 +49,8 @@ public function __construct( public function stream(FileInterface $file) { $response = $this->make($file); - - $stream = $this->manager->readStream($file->location()); + + $stream = $this->manager->disk($file->getDiskSlug())->readStream($file->path()); return $this->response->stream( function () use ($stream) {