@@ -333,10 +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- $ mtime = time ();
337- $ this ->knownMTimes ->set ($ path , $ mtime );
338- $ this ->getConnection ()->touch ($ this ->absPath ($ path ), $ mtime , $ mtime );
339- $ this ->getConnection ()->clearStatCache ();
336+ $ this ->touch ($ path , time ());
340337 });
341338 }
342339 return $ fh ;
@@ -360,18 +357,17 @@ public function fopen(string $path, string $mode) {
360357 }
361358
362359 public function touch (string $ path , ?int $ mtime = null ): bool {
363- try {
360+
361+ $ result = $ this ->getConnection ()->touch ($ this ->absPath ($ path ), $ mtime , $ mtime );
362+
363+ if ($ result ) {
364+ $ this ->getConnection ()->clearStatCache ($ this ->absPath ($ path ));
364365 if (!is_null ($ mtime )) {
365- return false ;
366- }
367- if (!$ this ->file_exists ($ path )) {
368- return $ this ->getConnection ()->put ($ this ->absPath ($ path ), '' );
369- } else {
370- return false ;
366+ $ this ->knownMTimes ->set ($ path , $ mtime );
371367 }
372- } catch (\Exception $ e ) {
373- return false ;
374368 }
369+
370+ return $ result ;
375371 }
376372
377373 /**
@@ -432,10 +428,8 @@ public function constructUrl(string $path): string {
432428 public function file_put_contents (string $ path , mixed $ data ): int |float |false {
433429 /** @psalm-suppress InternalMethod */
434430 $ 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 ();
431+
432+ $ this ->touch ($ path , time ());
439433
440434 if ($ result ) {
441435 return strlen ($ data );
@@ -456,10 +450,8 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
456450 /** @psalm-suppress InternalMethod */
457451 $ result = $ this ->getConnection ()->put ($ this ->absPath ($ path ), $ stream );
458452 fclose ($ stream );
459- $ mtime = time ();
460- $ this ->knownMTimes ->set ($ path , $ mtime );
461- $ this ->getConnection ()->touch ($ this ->absPath ($ path ), $ mtime , $ mtime );
462- $ this ->getConnection ()->clearStatCache ();
453+
454+ $ this ->touch ($ path , time ());
463455
464456 if ($ result ) {
465457 if ($ size === null ) {
0 commit comments