Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(files_trashbin): Fix all IStorage return types
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 26, 2024
commit 0356e9e82f8a16057dffd78a3436c5a2558533bc
32 changes: 9 additions & 23 deletions apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ public function __construct(
parent::__construct($parameters);
}

/**
* Deletes the given file by moving it into the trashbin.
*
* @param string $path path of file or folder to delete
*
* @return bool true if the operation succeeded, false otherwise
*/
public function unlink($path) {
public function unlink($path): bool {
if ($this->trashEnabled) {
try {
return $this->doDelete($path, 'unlink');
Expand All @@ -72,14 +65,7 @@ public function unlink($path) {
}
}

/**
* Deletes the given folder by moving it into the trashbin.
*
* @param string $path path of folder to delete
*
* @return bool true if the operation succeeded, false otherwise
*/
public function rmdir($path) {
public function rmdir($path): bool {
if ($this->trashEnabled) {
return $this->doDelete($path, 'rmdir');
} else {
Expand All @@ -94,7 +80,7 @@ public function rmdir($path) {
* @param $path
* @return bool
*/
protected function shouldMoveToTrash($path) {
protected function shouldMoveToTrash($path): bool {
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
$parts = explode('/', $normalized);
if (count($parts) < 4 || strpos($normalized, '/appdata_') === 0) {
Expand Down Expand Up @@ -132,7 +118,7 @@ protected function shouldMoveToTrash($path) {
* @param Node $node
* @return MoveToTrashEvent
*/
protected function createMoveToTrashEvent(Node $node) {
protected function createMoveToTrashEvent(Node $node): MoveToTrashEvent {
return new MoveToTrashEvent($node);
}

Expand All @@ -144,7 +130,7 @@ protected function createMoveToTrashEvent(Node $node) {
*
* @return bool true if the operation succeeded, false otherwise
*/
private function doDelete($path, $method) {
private function doDelete($path, $method): bool {
if (
!\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
|| (pathinfo($path, PATHINFO_EXTENSION) === 'part')
Expand All @@ -170,7 +156,7 @@ private function doDelete($path, $method) {
/**
* Setup the storage wrapper callback
*/
public static function setupStorage() {
public static function setupStorage(): void {
$trashManager = \OC::$server->get(ITrashManager::class);
$userManager = \OC::$server->get(IUserManager::class);
$logger = \OC::$server->get(LoggerInterface::class);
Expand All @@ -195,7 +181,7 @@ public function getMountPoint() {
return $this->mountPoint;
}

public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
$sourceIsTrashbin = $sourceStorage->instanceOfStorage(Storage::class);
try {
// the fallback for moving between storage involves a copy+delete
Expand All @@ -219,11 +205,11 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
}
}

protected function disableTrash() {
protected function disableTrash(): void {
$this->trashEnabled = false;
}

protected function enableTrash() {
protected function enableTrash(): void {
$this->trashEnabled = true;
}
}
4 changes: 2 additions & 2 deletions apps/files_trashbin/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
use Test\Traits\MountProviderTrait;

class TemporaryNoCross extends Temporary {
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) {
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null): bool {
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
}

public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
Expand Down