Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ public function fopen(string $path, string $mode) {
$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;
Expand Down Expand Up @@ -429,6 +432,11 @@ 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);
$mtime = time();
$this->knownMTimes->set($path, $mtime);
$this->getConnection()->touch($this->absPath($path), $mtime, $mtime);
$this->getConnection()->clearStatCache();

if ($result) {
return strlen($data);
} else {
Expand All @@ -448,6 +456,11 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
/** @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');
Expand Down
6 changes: 6 additions & 0 deletions apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Loading