@@ -333,7 +333,7 @@ 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+ $ this ->touch ($ path , time ());
337337 });
338338 }
339339 return $ fh ;
@@ -357,18 +357,17 @@ public function fopen(string $path, string $mode) {
357357 }
358358
359359 public function touch (string $ path , ?int $ mtime = null ): bool {
360- try {
360+
361+ $ result = $ this ->getConnection ()->touch ($ this ->absPath ($ path ), $ mtime , $ mtime );
362+
363+ if ($ result ) {
364+ $ this ->getConnection ()->clearStatCache ();
361365 if (!is_null ($ mtime )) {
362- return false ;
363- }
364- if (!$ this ->file_exists ($ path )) {
365- return $ this ->getConnection ()->put ($ this ->absPath ($ path ), '' );
366- } else {
367- return false ;
366+ $ this ->knownMTimes ->set ($ path , $ mtime );
368367 }
369- } catch (\Exception $ e ) {
370- return false ;
371368 }
369+
370+ return $ result ;
372371 }
373372
374373 /**
@@ -429,6 +428,9 @@ public function constructUrl(string $path): string {
429428 public function file_put_contents (string $ path , mixed $ data ): int |float |false {
430429 /** @psalm-suppress InternalMethod */
431430 $ result = $ this ->getConnection ()->put ($ this ->absPath ($ path ), $ data );
431+
432+ $ this ->touch ($ path , time ());
433+
432434 if ($ result ) {
433435 return strlen ($ data );
434436 } else {
@@ -448,6 +450,9 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
448450 /** @psalm-suppress InternalMethod */
449451 $ result = $ this ->getConnection ()->put ($ this ->absPath ($ path ), $ stream );
450452 fclose ($ stream );
453+
454+ $ this ->touch ($ path , time ());
455+
451456 if ($ result ) {
452457 if ($ size === null ) {
453458 throw new \Exception ('Failed to get written size from sftp storage wrapper ' );
0 commit comments