Skip to content
Merged
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
6 changes: 4 additions & 2 deletions lib/BlockingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ public function chown(string $path, int $uid, int $gid): Promise {
/**
* {@inheritdoc}
*/
public function touch(string $path): Promise {
return new Success((bool) \touch($path));
public function touch(string $path, int $time = null, int $atime = null): Promise {
$time = $time ?? \time();
$atime = $atime ?? $time;
return new Success((bool) \touch($path, $time, $atime));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ public function chown(string $path, int $uid, int $gid): Promise;
* If the file does not exist it will be created automatically.
*
* @param string $path
* @param int $time The touch time. If $time is not supplied, the current system time is used.
* @param int $atime The access time. If $atime is not supplied, value passed to the $time parameter is used.
* @return \Amp\Promise
*/
public function touch(string $path): Promise;
public function touch(string $path, int $time = null, int $atime = null): Promise;

/**
* Buffer the specified file's contents.
Expand Down
7 changes: 4 additions & 3 deletions lib/EioDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,15 @@ public function chown(string $path, int $uid, int $gid): Promise {
/**
* {@inheritdoc}
*/
public function touch(string $path): Promise {
$atime = $mtime = \time();
public function touch(string $path, int $time = null, int $atime = null): Promise {
$time = $time ?? \time();
$atime = $atime ?? $time;

$deferred = new Deferred;
$this->poll->listen($deferred->promise());

$priority = \EIO_PRI_DEFAULT;
\eio_utime($path, $atime, $mtime, $priority, [$this, "onGenericResult"], $deferred);
\eio_utime($path, $atime, $time, $priority, [$this, "onGenericResult"], $deferred);

return $deferred->promise();
}
Expand Down
1 change: 1 addition & 0 deletions lib/Internal/FileTask.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Amp\File\Internal;

use Amp\File\BlockingDriver;
Expand Down
4 changes: 2 additions & 2 deletions lib/ParallelDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public function lstat(string $path): Promise {
/**
* {@inheritdoc}
*/
public function touch(string $path): Promise {
return new Coroutine($this->runFileTask(new Internal\FileTask("touch", [$path])));
public function touch(string $path, int $time = null, int $atime = null): Promise {
return new Coroutine($this->runFileTask(new Internal\FileTask("touch", [$path, $time, $atime])));
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/UvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,14 @@ public function chown(string $path, int $uid, int $gid): Promise {
/**
* {@inheritdoc}
*/
public function touch(string $path): Promise {
$atime = $mtime = time();
public function touch(string $path, int $time = null, int $atime = null): Promise {
$time = $time ?? \time();
$atime = $atime ?? $time;

$deferred = new Deferred;
$this->poll->listen($deferred->promise());

\uv_fs_utime($this->loop, $path, $mtime, $atime, function () use ($deferred) {
\uv_fs_utime($this->loop, $path, $time, $atime, function () use ($deferred) {
// The uv_fs_utime() callback does not receive any args at this time
$deferred->resolve(true);
});
Expand Down
6 changes: 4 additions & 2 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ function chown(string $path, int $uid, int $gid = -1): Promise {
* If the file does not exist it will be created automatically.
*
* @param string $path
* @param int $time The touch time. If $time is not supplied, the current system time is used.
* @param int $atime The access time. If $atime is not supplied, value passed to the $time parameter is used.
* @return \Amp\Promise<null>
*/
function touch(string $path): Promise {
return filesystem()->touch($path);
function touch(string $path, int $time = null, int $atime = null): Promise {
return filesystem()->touch($path, $time, $atime);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions test/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ public function testTouch() {
yield File\put($touch, "touch me");

$oldStat = (yield File\stat($touch));
sleep(1);
yield File\touch($touch);
yield File\touch($touch, \time() + 10, \time() + 20);
File\StatCache::clear($touch);
$newStat = (yield File\stat($touch));
yield File\unlink($touch);
Expand Down