Skip to content
Closed
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
36 changes: 27 additions & 9 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
namespace OCA\Files_External\Lib\Storage;

use DateTimeImmutable;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\CountWrapper;
use Icewind\Streams\IteratorDirectory;
Expand Down Expand Up @@ -50,11 +51,7 @@ public function __construct($params) {
$this->username = $params['user'];
$this->password = $params['password'];
if (isset($params['secure'])) {
if (is_string($params['secure'])) {
$this->secure = ($params['secure'] === 'true');
} else {
$this->secure = (bool)$params['secure'];
}
$this->secure = is_string($params['secure']) ? ($params['secure'] === 'true') : (bool) $params['secure'];
} else {
$this->secure = false;
}
Expand Down Expand Up @@ -123,7 +120,7 @@ public function filemtime($path) {
return $item['type'] === 'cdir';
}));
if ($currentDir) {
$time = \DateTime::createFromFormat('YmdHis', $currentDir['modify'] ?? '');
$time = $this->parseTimeVal($currentDir['modify'] ?? '');
if ($time === false) {
throw new \Exception("Invalid date format for directory: $currentDir");
}
Expand Down Expand Up @@ -355,10 +352,12 @@ public function getDirectoryContent($directory): \Traversable {

$data = [];
$data['mimetype'] = $isDir ? FileInfo::MIMETYPE_FOLDER : $mimeTypeDetector->detectPath($name);
$data['mtime'] = \DateTime::createFromFormat('YmdGis', $file['modify'])->getTimestamp();
if ($data['mtime'] === false) {
$time = $this->parseTimeVal($file['modify'] ?? '');
if ($time === false) {
$data['mtime'] = time();
}
} else {
$data['mtime'] = $time->getTimestamp();
}
if ($isDir) {
$data['size'] = -1; //unknown
} elseif (isset($file['size'])) {
Expand All @@ -374,4 +373,23 @@ public function getDirectoryContent($directory): \Traversable {
yield $data;
}
}

/**
* @param string $timeVal
* @return DateTimeImmutable|false
*/
private function parseTimeVal(string $timeVal) {
if ($timeVal === '') {
return false;
}

// https://www.rfc-editor.org/rfc/rfc3659#section-2.3
if (strlen($timeVal) === 14) {
$format = 'YmdGis';
} else {
$format = 'YmdGis.u';
}

return DateTimeImmutable::createFromFormat($format, $timeVal);
}
}