diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php
index afdd5bb972463..c9ff9cdd92447 100644
--- a/apps/files_external/lib/Lib/Storage/SFTP.php
+++ b/apps/files_external/lib/Lib/Storage/SFTP.php
@@ -341,19 +341,14 @@ public function fopen(string $path, string $mode) {
}
public function touch(string $path, ?int $mtime = null): bool {
- try {
- if (!is_null($mtime)) {
- return false;
- }
- if (!$this->file_exists($path)) {
- $this->getConnection()->put($this->absPath($path), '');
- } else {
- return false;
- }
- } catch (\Exception $e) {
- return false;
+
+ $result = $this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
+
+ if ($result) {
+ $this->getConnection()->clearStatCache();
}
- return true;
+
+ return $result;
}
/**
@@ -408,6 +403,9 @@ public function constructUrl(string $path): string {
public function file_put_contents(string $path, mixed $data): int|float|false {
/** @psalm-suppress InternalMethod */
$result = $this->getConnection()->put($this->absPath($path), $data);
+
+ $this->touch($path, time());
+
if ($result) {
return strlen($data);
} else {
@@ -427,6 +425,9 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
/** @psalm-suppress InternalMethod */
$result = $this->getConnection()->put($this->absPath($path), $stream);
fclose($stream);
+
+ $this->touch($path, time());
+
if ($result) {
if ($size === null) {
throw new \Exception('Failed to get written size from sftp storage wrapper');
diff --git a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
index d64e89b546217..c6713de193e85 100644
--- a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
+++ b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
@@ -32,6 +32,8 @@ class SFTPWriteStream implements File {
private $buffer = '';
+ private string $path;
+
public static function register($protocol = 'sftpwrite') {
if (in_array($protocol, stream_get_wrappers(), true)) {
return false;
@@ -71,6 +73,8 @@ public function stream_open($path, $mode, $options, &$opened_path) {
}
$remote_file = $this->sftp->_realpath($path);
+
+ $this->path = $remote_file;
if ($remote_file === false) {
return false;
}
@@ -160,6 +164,8 @@ public function stream_close() {
if (!$this->sftp->_close_handle($this->handle)) {
return false;
}
+ $this->sftp->touch($this->path, time(), time());
+
return true;
}
}
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 63288887cd395..4874a4f878a61 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -802,11 +802,6 @@
]]>
-
-
-
-
-
getCode()]]>