This commit is contained in:
backportbot[bot] 2026-04-02 22:57:34 +00:00 committed by GitHub
commit 3d837339df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 11 deletions

View file

@ -333,7 +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 {
$this->knownMTimes->set($path, time());
$this->touch($path, time());
});
}
return $fh;
@ -357,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();
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;
}
/**
@ -429,6 +428,9 @@ 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);
$this->touch($path, time());
if ($result) {
return strlen($data);
} else {
@ -448,6 +450,9 @@ class SFTP extends Common {
/** @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');

View file

@ -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;
}
}

View file

@ -1406,7 +1406,6 @@
<InternalMethod>
<code><![CDATA[getLocalFile]]></code>
<code><![CDATA[new View('/' . $userId . '/files_external')]]></code>
<code><![CDATA[put]]></code>
</InternalMethod>
</file>
<file src="apps/files_external/lib/Lib/Storage/SMB.php">