mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix: manually set modified time to SFTP files after editing
Signed-off-by: Hendrik Leidinger <hendrik.leidinger@nextcloud.com>
This commit is contained in:
parent
8e6be5bd4f
commit
b350164c3d
2 changed files with 20 additions and 1 deletions
|
|
@ -333,7 +333,10 @@ class SFTP extends Common {
|
|||
$fh = fopen('sftpwrite://' . trim($absPath, '/'), 'w', false, $context);
|
||||
if ($fh) {
|
||||
$fh = CallbackWrapper::wrap($fh, null, null, function () use ($path): void {
|
||||
$this->knownMTimes->set($path, time());
|
||||
$mtime = time();
|
||||
$this->knownMTimes->set($path, $mtime);
|
||||
$this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
|
||||
$this->getConnection()->clearStatCache();
|
||||
});
|
||||
}
|
||||
return $fh;
|
||||
|
|
@ -429,6 +432,11 @@ 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();
|
||||
|
||||
if ($result) {
|
||||
return strlen($data);
|
||||
} else {
|
||||
|
|
@ -448,6 +456,11 @@ 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();
|
||||
|
||||
if ($result) {
|
||||
if ($size === null) {
|
||||
throw new \Exception('Failed to get written size from sftp storage wrapper');
|
||||
|
|
|
|||
|
|
@ -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 @@ class SFTPWriteStream implements File {
|
|||
}
|
||||
|
||||
$remote_file = $this->sftp->_realpath($path);
|
||||
|
||||
$this->path = $remote_file;
|
||||
if ($remote_file === false) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -160,6 +164,8 @@ class SFTPWriteStream implements File {
|
|||
if (!$this->sftp->_close_handle($this->handle)) {
|
||||
return false;
|
||||
}
|
||||
$this->sftp->touch($this->path, time(), time());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue