Skip to content

Commit 6d26c71

Browse files
rikledsusnux
authored andcommitted
fix: manually set modified time to SFTP files after editing
Signed-off-by: Hendrik Leidinger <hendrik.leidinger@nextcloud.com>
1 parent 5acf387 commit 6d26c71

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

apps/files_external/lib/Lib/Storage/SFTP.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ public function fopen(string $path, string $mode) {
333333
$fh = fopen('sftpwrite://' . trim($absPath, '/'), 'w', false, $context);
334334
if ($fh) {
335335
$fh = CallbackWrapper::wrap($fh, null, null, function () use ($path): void {
336-
$this->knownMTimes->set($path, time());
336+
$mtime = time();
337+
$this->knownMTimes->set($path, $mtime);
338+
$this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
339+
$this->getConnection()->clearStatCache();
337340
});
338341
}
339342
return $fh;
@@ -429,6 +432,11 @@ public function constructUrl(string $path): string {
429432
public function file_put_contents(string $path, mixed $data): int|float|false {
430433
/** @psalm-suppress InternalMethod */
431434
$result = $this->getConnection()->put($this->absPath($path), $data);
435+
$mtime = time();
436+
$this->knownMTimes->set($path, $mtime);
437+
$this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
438+
$this->getConnection()->clearStatCache();
439+
432440
if ($result) {
433441
return strlen($data);
434442
} else {
@@ -448,6 +456,11 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
448456
/** @psalm-suppress InternalMethod */
449457
$result = $this->getConnection()->put($this->absPath($path), $stream);
450458
fclose($stream);
459+
$mtime = time();
460+
$this->knownMTimes->set($path, $mtime);
461+
$this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
462+
$this->getConnection()->clearStatCache();
463+
451464
if ($result) {
452465
if ($size === null) {
453466
throw new \Exception('Failed to get written size from sftp storage wrapper');

apps/files_external/lib/Lib/Storage/SFTPWriteStream.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class SFTPWriteStream implements File {
3232

3333
private $buffer = '';
3434

35+
private string $path;
36+
3537
public static function register($protocol = 'sftpwrite') {
3638
if (in_array($protocol, stream_get_wrappers(), true)) {
3739
return false;
@@ -71,6 +73,8 @@ public function stream_open($path, $mode, $options, &$opened_path) {
7173
}
7274

7375
$remote_file = $this->sftp->_realpath($path);
76+
77+
$this->path = $remote_file;
7478
if ($remote_file === false) {
7579
return false;
7680
}
@@ -160,6 +164,8 @@ public function stream_close() {
160164
if (!$this->sftp->_close_handle($this->handle)) {
161165
return false;
162166
}
167+
$this->sftp->touch($this->path, time(), time());
168+
163169
return true;
164170
}
165171
}

0 commit comments

Comments
 (0)