Skip to content
Merged
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
19 changes: 14 additions & 5 deletions src/Nextcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final public function deleteDirectory(string $dirname): void
}

/**
* Get all the meta data of a file or directory.
* Get all the meta data of a file
*
* @param string $path
*
Expand Down Expand Up @@ -170,7 +170,12 @@ final public function visibility(string $path): FileAttributes
*/
final public function fileExists(string $path): bool
{
return $this->folder->nodeExists($path);
try {
$node = $this->folder->get($path);
return !$this->isDirectory($node);
} catch (\OCP\Files\NotFoundException $exception) {
return false;
}
}

/**
Expand All @@ -182,7 +187,12 @@ final public function fileExists(string $path): bool
*/
final public function directoryExists(string $path): bool
{
return $this->folder->nodeExists($path);
try {
$node = $this->folder->get($path);
return $this->isDirectory($node);
} catch (\OCP\Files\NotFoundException $exception) {
return false;
}
}

/**
Expand Down Expand Up @@ -384,10 +394,9 @@ private function isDirectory(\OCP\Files\Node $node)
private function normalizeNodeInfo(\OCP\Files\Node $node, array $metaData = []) : array
{
return array_merge([
'mimetype' => $this->isDirectory($node) ? "directory" : $node->getMimetype(),
'mimetype' => $node->getMimetype(),
'path' => substr($node->getPath(), strlen($this->folder->getPath())+1),
'size' => $node->getSize(),
'basename' => basename($node->getPath()),
'timestamp' => $node->getMTime(),
'type' => $node->getType(),
// @FIXME: Use $node->getPermissions() to set private or public
Expand Down
14 changes: 7 additions & 7 deletions src/NextcloudCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function getCalendarId($path) {
}

/**
* Get all the meta data of a file or directory.
* Get all the meta data of a file.
*
* @param string $path
*
Expand Down Expand Up @@ -217,7 +217,7 @@ final public function fileExists(string $path): bool

$calendarId = $this->getCalendarId($path);
if ($calendarId !== null) {
return true;
return false;
} else {
list($calendar, $filename) = $this->splitPath($path);
$calendarId = $this->getCalendarId($calendar);
Expand All @@ -229,7 +229,11 @@ final public function fileExists(string $path): bool

final public function directoryExists(string $path): bool
{
return $this->fileExists($path);
$calendarId = $this->getCalendarId($path);
if ($calendarId !== null) {
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -337,7 +341,6 @@ final public function readStream(string $path): void

private function normalizeAcl($acl) {
return [
'basename' => '.acl',
'contents' => $acl,
'mimetype' => 'text/turtle',
'path' => '.acl',
Expand All @@ -354,7 +357,6 @@ private function normalizeCalendarItem($calendarItem, $basePath) {
}

return [
'basename' => $calendarItem['uri'],
'contents' => $calendarItem['calendardata'],
'mimetype' => 'text/calendar',
'path' => $basePath . '/' . $calendarItem['uri'],
Expand All @@ -368,8 +370,6 @@ private function normalizeCalendarItem($calendarItem, $basePath) {
private function normalizeCalendar($calendar)
{
return [
'basename' => basename($calendar['uri']),
'mimetype' => 'directory',
'path' => $calendar['uri'],
'size' => 0,
'timestamp' => 0,
Expand Down
12 changes: 6 additions & 6 deletions src/NextcloudContacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ final public function fileExists(string $path): bool

$addressBookId = $this->getAddressBookId($path);
if ($addressBookId !== null) {
return true;
return false;
} else {
list($addressBook, $filename) = $this->splitPath($path);
$addressBookId = $this->getAddressBookId($addressBook);
Expand All @@ -235,7 +235,11 @@ final public function fileExists(string $path): bool
*/
final public function directoryExists(string $path): bool
{
return $this->fileExists($path);
$addressBookId = $this->getAddressBookId($path);
if ($addressBookId !== null) {
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -348,7 +352,6 @@ final public function readStream(string $path): void

private function normalizeAcl($acl) {
return [
'basename' => '.acl',
'contents' => $acl,
'mimetype' => 'text/turtle',
'path' => '.acl',
Expand All @@ -365,7 +368,6 @@ private function normalizeCard($card, $basePath) {
}

return [
'basename' => $card['uri'],
'contents' => $card['carddata'],
'mimetype' => 'text/vcard',
'path' => $basePath . '/' . $card['uri'],
Expand All @@ -379,8 +381,6 @@ private function normalizeCard($card, $basePath) {
private function normalizeAddressBook($addressBook)
{
return [
'basename' => basename($addressBook['uri']),
'mimetype' => 'directory',
'path' => $addressBook['uri'],
'size' => 0,
'timestamp' => 0,
Expand Down
7 changes: 4 additions & 3 deletions src/NextcloudProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ final public function fileExists(string $path): bool
*/
final public function directoryExists(string $path): bool
{
return $this->fileExists($path);
if ($path === '/') {
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -253,7 +256,6 @@ final public function readStream(string $path): void

private function normalizeAcl($acl) {
return [
'basename' => '.acl',
'contents' => $acl,
'mimetype' => 'text/turtle',
'path' => '.acl',
Expand All @@ -267,7 +269,6 @@ private function normalizeAcl($acl) {
private function normalizeProfile() {
$profile = $this->profile;
return [
'basename' => 'card',
'contents' => $profile,
'mimetype' => 'text/turtle',
'path' => "card",
Expand Down
Loading