Skip to content

Commit

Permalink
log entries that are hidden during file listing
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 15, 2018
1 parent 0757c52 commit 6242e2f
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class SMB extends Common implements INotifyStorage {
*/
protected $statCache;

/** @var ILogger */
protected $logger;

public function __construct($params) {
if (!isset($params['host'])) {
throw new \Exception('Invalid configuration, no host provided');
Expand All @@ -92,6 +95,12 @@ public function __construct($params) {
throw new \Exception('Invalid configuration, no credentials provided');
}

if (isset($params['logger'])) {
$this->logger = $params['logger'];
} else {
$this->logger = \OC::$server->getLogger();
}

$serverFactory = new ServerFactory();
$this->server = $serverFactory->createServer($params['host'], $auth);
$this->share = $this->server->getShare(trim($params['share'], '/'));
Expand Down Expand Up @@ -155,7 +164,7 @@ protected function getFileInfo($path) {
}
return $this->statCache[$path];
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while getting file info']);
$this->logger->logException($e, ['message' => 'Error while getting file info']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand All @@ -174,15 +183,18 @@ protected function getFolderContents($path) {
}
return array_filter($files, function (IFileInfo $file) {
try {
$this->logger->debug('hiding hidden file ' . $file->getName());
return !$file->isHidden();
} catch (ForbiddenException $e) {
$this->logger->logException($e, ['level' => ILogger::DEBUG, 'message' => 'Hiding forbidden entry ' . $file->getName()]);
return false;
} catch (NotFoundException $e) {
$this->logger->logException($e, ['level' => ILogger::DEBUG, 'message' => 'Hiding not found entry ' . $file->getName()]);
return false;
}
});
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while getting folder content']);
$this->logger->logException($e, ['message' => 'Error while getting folder content']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand Down Expand Up @@ -225,19 +237,19 @@ public function rename($source, $target, $retry = true) {
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget, false);
} else {
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
$this->logger->logException($e, ['level' => ILogger::WARN]);
return false;
}
} catch (InvalidArgumentException $e) {
if ($retry) {
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget, false);
} else {
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
$this->logger->logException($e, ['level' => ILogger::WARN]);
return false;
}
} catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
$this->logger->logException($e, ['level' => ILogger::WARN]);
return false;
}
unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
Expand Down Expand Up @@ -320,7 +332,7 @@ public function unlink($path) {
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while deleting file']);
$this->logger->logException($e, ['message' => 'Error while deleting file']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand Down Expand Up @@ -405,7 +417,7 @@ public function fopen($path, $mode) {
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while opening file']);
$this->logger->logException($e, ['message' => 'Error while opening file']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand All @@ -432,7 +444,7 @@ public function rmdir($path) {
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while removing folder']);
$this->logger->logException($e, ['message' => 'Error while removing folder']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand All @@ -446,7 +458,7 @@ public function touch($path, $time = null) {
}
return false;
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while creating file']);
$this->logger->logException($e, ['message' => 'Error while creating file']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
}
}
Expand Down Expand Up @@ -482,7 +494,7 @@ public function mkdir($path) {
$this->share->mkdir($path);
return true;
} catch (ConnectException $e) {
\OC::$server->getLogger()->logException($e, ['message' => 'Error while creating folder']);
$this->logger->logException($e, ['message' => 'Error while creating folder']);
throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
} catch (Exception $e) {
return false;
Expand Down Expand Up @@ -556,7 +568,7 @@ public function test() {
try {
return parent::test();
} catch (Exception $e) {
\OC::$server->getLogger()->logException($e);
$this->logger->logException($e);
return false;
}
}
Expand Down

0 comments on commit 6242e2f

Please sign in to comment.