Skip to content

Commit dfa17a0

Browse files
committed
sftp psalm fixes
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent c264903 commit dfa17a0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

apps/files_external/lib/Lib/Storage/SFTP.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use OC\Files\Storage\Common;
4444
use OCP\Constants;
4545
use OCP\Files\FileInfo;
46+
use OCP\Files\IMimeTypeDetector;
4647
use phpseclib\Net\SFTP\Stream;
4748

4849
/**
@@ -61,6 +62,7 @@ class SFTP extends Common {
6162
* @var \phpseclib\Net\SFTP
6263
*/
6364
protected $client;
65+
private IMimeTypeDetector $mimeTypeDetector;
6466

6567
const COPY_CHUNK_SIZE = 8 * 1024 * 1024;
6668

@@ -118,6 +120,7 @@ public function __construct($params) {
118120

119121
$this->root = '/' . ltrim($this->root, '/');
120122
$this->root = rtrim($this->root, '/') . '/';
123+
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
121124
}
122125

123126
/**
@@ -460,7 +463,7 @@ public function rename($source, $target) {
460463
}
461464

462465
/**
463-
* {@inheritdoc}
466+
* @return array{mtime: int, size: int, ctime: int}|false
464467
*/
465468
public function stat($path) {
466469
try {
@@ -499,9 +502,12 @@ public function file_put_contents($path, $data) {
499502

500503
public function writeStream(string $path, $stream, int $size = null): int {
501504
if ($size === null) {
502-
$stream = CountWrapper::wrap($stream, function ($writtenSize) use (&$size) {
505+
$stream = CountWrapper::wrap($stream, function (int $writtenSize) use (&$size) {
503506
$size = $writtenSize;
504507
});
508+
if (!$stream) {
509+
throw new \Exception("Failed to wrap stream");
510+
}
505511
}
506512
/** @psalm-suppress InternalMethod */
507513
$result = $this->getConnection()->put($this->absPath($path), $stream);
@@ -559,26 +565,23 @@ public function getMetaData($path) {
559565
}
560566

561567
if ($stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
562-
$permissions = Constants::PERMISSION_ALL;
568+
$stat['permissions'] = Constants::PERMISSION_ALL;
563569
} else {
564-
$permissions = Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
570+
$stat['permissions'] = Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
565571
}
566572

567573
if ($stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
568574
$stat['size'] = -1;
569575
$stat['mimetype'] = FileInfo::MIMETYPE_FOLDER;
570576
} else {
571-
$stat['mimetype'] = \OC::$server->getMimeTypeDetector()->detectPath($path);
577+
$stat['mimetype'] = $this->mimeTypeDetector->detectPath($path);
572578
}
573579

574580
$stat['etag'] = $this->getETag($path);
575581
$stat['storage_mtime'] = $stat['mtime'];
576-
$stat['permissions'] = $permissions;
577582
$stat['name'] = basename($path);
578583

579584
$keys = ['size', 'mtime', 'mimetype', 'etag', 'storage_mtime', 'permissions', 'name'];
580585
return array_intersect_key($stat, array_flip($keys));
581586
}
582-
583-
584587
}

apps/files_external/lib/Lib/Storage/SFTPReadStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function stream_seek($offset, $whence = SEEK_SET) {
137137
return true;
138138
}
139139

140-
private function seekTo(int $offset) {
140+
private function seekTo(int $offset): void {
141141
$this->internalPosition = $offset;
142142
$this->readPosition = $offset;
143143
$this->buffer = '';

0 commit comments

Comments
 (0)