Skip to content

Commit

Permalink
Merge pull request #34020 from nextcloud/logical-op
Browse files Browse the repository at this point in the history
Switch logical operators (and|or)
  • Loading branch information
PVince81 authored Sep 16, 2022
2 parents 703dd64 + 5300f0d commit b3ca186
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/private/Files/Storage/Wrapper/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function getQuota(): int {
}
$this->quota = $quotaCallback();
}

return $this->quota;
}

Expand All @@ -84,18 +85,14 @@ protected function getSize($path, $storage = null) {
if ($rootInfo) {
return $rootInfo->getSize(true);
}
return \OCP\Files\FileInfo::SPACE_NOT_COMPUTED;
return FileInfo::SPACE_NOT_COMPUTED;
} else {
if (is_null($storage)) {
$cache = $this->getCache();
} else {
$cache = $storage->getCache();
}
$cache = is_null($storage) ? $this->getCache() : $storage->getCache();
$data = $cache->get($path);
if ($data instanceof ICacheEntry and isset($data['size'])) {
if ($data instanceof ICacheEntry && isset($data['size'])) {
return $data['size'];
} else {
return \OCP\Files\FileInfo::SPACE_NOT_COMPUTED;
return FileInfo::SPACE_NOT_COMPUTED;
}
}
}
Expand All @@ -115,16 +112,12 @@ public function free_space($path) {
} else {
$used = $this->getSize($this->sizeRoot);
if ($used < 0) {
return \OCP\Files\FileInfo::SPACE_NOT_COMPUTED;
return FileInfo::SPACE_NOT_COMPUTED;
} else {
$free = $this->storage->free_space($path);
$quotaFree = max($this->getQuota() - $used, 0);
// if free space is known
if ($free >= 0) {
$free = min($free, $quotaFree);
} else {
$free = $quotaFree;
}
$free = $free >= 0 ? min($free, $quotaFree) : $quotaFree;
return $free;
}
}
Expand All @@ -142,7 +135,7 @@ public function file_put_contents($path, $data) {
return $this->storage->file_put_contents($path, $data);
}
$free = $this->free_space($path);
if ($free < 0 or strlen($data) < $free) {
if ($free < 0 || strlen($data) < $free) {
return $this->storage->file_put_contents($path, $data);
} else {
return false;
Expand All @@ -161,7 +154,7 @@ public function copy($source, $target) {
return $this->storage->copy($source, $target);
}
$free = $this->free_space($target);
if ($free < 0 or $this->getSize($source) < $free) {
if ($free < 0 || $this->getSize($source) < $free) {
return $this->storage->copy($source, $target);
} else {
return false;
Expand Down Expand Up @@ -191,6 +184,7 @@ public function fopen($path, $mode) {
}
}
}

return $source;
}

Expand Down Expand Up @@ -225,7 +219,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
$free = $this->free_space($targetInternalPath);
if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
if ($free < 0 || $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
} else {
return false;
Expand All @@ -243,7 +237,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
$free = $this->free_space($targetInternalPath);
if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
if ($free < 0 || $this->getSize($sourceInternalPath, $sourceStorage) < $free) {
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
} else {
return false;
Expand Down

0 comments on commit b3ca186

Please sign in to comment.