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
fix ftp external storage with filezilla server
- filezilla doesn't like "" as parameter for `mdtm` (all others seem fine)
- filezilla sends fractional modified date

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 30, 2023
commit fd0ef588b4d33871f82d5619432799477b88862e
12 changes: 7 additions & 5 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public function filemtime($path) {
return $item['type'] === 'cdir';
}));
if ($currentDir) {
$time = \DateTime::createFromFormat('YmdHis', $currentDir['modify'] ?? '');
[$modify] = explode('.', $currentDir['modify'] ?? '', 2);
$time = \DateTime::createFromFormat('YmdHis', $modify);
if ($time === false) {
throw new \Exception("Invalid date format for directory: $currentDir");
}
Expand Down Expand Up @@ -355,10 +356,11 @@ 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) {
$data['mtime'] = time();
}

// strip fractional seconds
[$modify] = explode('.', $file['modify'], 2);
$mtime = \DateTime::createFromFormat('YmdGis', $modify);
$data['mtime'] = $mtime === false ? time() : $mtime->getTimestamp();
if ($isDir) {
$data['size'] = -1; //unknown
} elseif (isset($file['size'])) {
Expand Down
10 changes: 8 additions & 2 deletions apps/files_external/lib/Lib/Storage/FtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ public function rename(string $source, string $target) {
return @ftp_rename($this->connection, $source, $target);
}

public function mdtm(string $path) {
return @ftp_mdtm($this->connection, $path);
public function mdtm(string $path): int {
$result = @ftp_mdtm($this->connection, $path);

// filezilla doesn't like empty path with mdtm
if ($result === -1 && $path === "") {
$result = @ftp_mdtm($this->connection, "/");
}
return $result;
}

public function size(string $path) {
Expand Down