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
Prev Previous commit
chore: Reapply coding standards
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Feb 10, 2025
commit f9e62dc9608e5f334690db2c084ef6f02fb047c3
10 changes: 5 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function downloadUpdate(): void {
throw new \Exception('Response from update server is missing url');
}

$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$saveLocation = $storageLocation . basename($response['url']);
$this->previousProgress = 0;

Expand Down Expand Up @@ -594,7 +594,7 @@ public function downloadUpdate(): void {
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => array($this, 'downloadProgressCallback'),
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
CURLOPT_FILE => $fp,
CURLOPT_USERAGENT => 'Nextcloud Updater',
]);
Expand Down Expand Up @@ -641,7 +641,7 @@ public function downloadUpdate(): void {
} else {
// download succeeded
$info = curl_getinfo($ch);
$this->silentLog("[info] download stats: size=" . $this->formatBytes((int)$info['size_download']) . " bytes; total_time=" . round($info['total_time'], 2) . " secs; avg speed=" . $this->formatBytes((int)$info['speed_download']) . "/sec");
$this->silentLog('[info] download stats: size=' . $this->formatBytes((int)$info['size_download']) . ' bytes; total_time=' . round($info['total_time'], 2) . ' secs; avg speed=' . $this->formatBytes((int)$info['speed_download']) . '/sec');
}

curl_close($ch);
Expand All @@ -657,14 +657,14 @@ private function downloadProgressCallback(\CurlHandle $resource, int $download_s
$this->previousProgress = $progress;
// log every 2% increment for the first 10% then only log every 10% increment after that
if ($progress % 10 === 0 || ($progress < 10 && $progress % 2 === 0)) {
$this->silentLog("[info] download progress: $progress% (" . $this->formatBytes($downloaded) . " of " . $this->formatBytes($download_size) . ")");
$this->silentLog("[info] download progress: $progress% (" . $this->formatBytes($downloaded) . ' of ' . $this->formatBytes($download_size) . ')');
}
}
}
}

private function formatBytes(int $bytes, int $precision = 2): string {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$units = ['B', 'KB', 'MB', 'GB', 'TB'];

$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
Expand Down
10 changes: 5 additions & 5 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function downloadUpdate(): void {
throw new \Exception('Response from update server is missing url');
}

$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$saveLocation = $storageLocation . basename($response['url']);
$this->previousProgress = 0;

Expand Down Expand Up @@ -576,7 +576,7 @@ public function downloadUpdate(): void {
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => array($this, 'downloadProgressCallback'),
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
CURLOPT_FILE => $fp,
CURLOPT_USERAGENT => 'Nextcloud Updater',
]);
Expand Down Expand Up @@ -623,7 +623,7 @@ public function downloadUpdate(): void {
} else {
// download succeeded
$info = curl_getinfo($ch);
$this->silentLog("[info] download stats: size=" . $this->formatBytes((int)$info['size_download']) . " bytes; total_time=" . round($info['total_time'], 2) . " secs; avg speed=" . $this->formatBytes((int)$info['speed_download']) . "/sec");
$this->silentLog('[info] download stats: size=' . $this->formatBytes((int)$info['size_download']) . ' bytes; total_time=' . round($info['total_time'], 2) . ' secs; avg speed=' . $this->formatBytes((int)$info['speed_download']) . '/sec');
}

curl_close($ch);
Expand All @@ -639,14 +639,14 @@ private function downloadProgressCallback(\CurlHandle $resource, int $download_s
$this->previousProgress = $progress;
// log every 2% increment for the first 10% then only log every 10% increment after that
if ($progress % 10 === 0 || ($progress < 10 && $progress % 2 === 0)) {
$this->silentLog("[info] download progress: $progress% (" . $this->formatBytes($downloaded) . " of " . $this->formatBytes($download_size) . ")");
$this->silentLog("[info] download progress: $progress% (" . $this->formatBytes($downloaded) . ' of ' . $this->formatBytes($download_size) . ')');
}
}
}
}

private function formatBytes(int $bytes, int $precision = 2): string {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$units = ['B', 'KB', 'MB', 'GB', 'TB'];

$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
Expand Down
Binary file modified updater.phar
Binary file not shown.