From 88d3e0583ac9731cc8b585b53714af586799392e Mon Sep 17 00:00:00 2001 From: Hendrik Leidinger Date: Thu, 26 Mar 2026 09:49:09 -0700 Subject: [PATCH] fix: modified touch function of the SFTP storage to update mtimes instead Signed-off-by: Hendrik Leidinger --- apps/files_external/lib/Lib/Storage/SFTP.php | 34 ++++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index 91d3e77c810..62a4a5174ee 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -333,10 +333,7 @@ class SFTP extends Common { $fh = fopen('sftpwrite://' . trim($absPath, '/'), 'w', false, $context); if ($fh) { $fh = CallbackWrapper::wrap($fh, null, null, function () use ($path): void { - $mtime = time(); - $this->knownMTimes->set($path, $mtime); - $this->getConnection()->touch($this->absPath($path), $mtime, $mtime); - $this->getConnection()->clearStatCache(); + $this->touch($path, time()); }); } return $fh; @@ -360,18 +357,17 @@ class SFTP extends Common { } public function touch(string $path, ?int $mtime = null): bool { - try { + + $result = $this->getConnection()->touch($this->absPath($path), $mtime, $mtime); + + if ($result) { + $this->getConnection()->clearStatCache($this->absPath($path)); if (!is_null($mtime)) { - return false; + $this->knownMTimes->set($path, $mtime); } - if (!$this->file_exists($path)) { - return $this->getConnection()->put($this->absPath($path), ''); - } else { - return false; - } - } catch (\Exception $e) { - return false; } + + return $result; } /** @@ -432,10 +428,8 @@ class SFTP extends Common { public function file_put_contents(string $path, mixed $data): int|float|false { /** @psalm-suppress InternalMethod */ $result = $this->getConnection()->put($this->absPath($path), $data); - $mtime = time(); - $this->knownMTimes->set($path, $mtime); - $this->getConnection()->touch($this->absPath($path), $mtime, $mtime); - $this->getConnection()->clearStatCache(); + + $this->touch($path, time()); if ($result) { return strlen($data); @@ -456,10 +450,8 @@ class SFTP extends Common { /** @psalm-suppress InternalMethod */ $result = $this->getConnection()->put($this->absPath($path), $stream); fclose($stream); - $mtime = time(); - $this->knownMTimes->set($path, $mtime); - $this->getConnection()->touch($this->absPath($path), $mtime, $mtime); - $this->getConnection()->clearStatCache(); + + $this->touch($path, time()); if ($result) { if ($size === null) {