Skip to content

Commit

Permalink
fix ftp external storage with filezilla server
Browse files Browse the repository at this point in the history
- 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 1, 2023
1 parent 9650685 commit 051c7ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 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'] ?? '');
$time = \DateTime::createFromFormat('YmdHis', $modify);
if ($time === false) {
throw new \Exception("Invalid date format for directory: $currentDir");
}
Expand Down Expand Up @@ -355,7 +356,10 @@ public function getDirectoryContent($directory): \Traversable {

$data = [];
$data['mimetype'] = $isDir ? FileInfo::MIMETYPE_FOLDER : $mimeTypeDetector->detectPath($name);
$data['mtime'] = \DateTime::createFromFormat('YmdGis', $file['modify'])->getTimestamp();

// strip fractional seconds
[$modify] = explode('.', $file['modify']);
$data['mtime'] = \DateTime::createFromFormat('YmdGis', $modify)->getTimestamp();
if ($data['mtime'] === false) {
$data['mtime'] = time();
}
Expand Down
8 changes: 7 additions & 1 deletion apps/files_external/lib/Lib/Storage/FtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ public function rename(string $source, string $target) {
}

public function mdtm(string $path) {
return @ftp_mdtm($this->connection, $path);
$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

0 comments on commit 051c7ee

Please sign in to comment.