Skip to content

Commit 8a802e0

Browse files
committed
Merge pull request #42 from clue-labs/copy
Pass path to containerCopy() and containerCopyStream() instead of config
2 parents 4923646 + a1522d1 commit 8a802e0

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

examples/copy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
use Clue\CaretNotation\Encoder;
1313

1414
$container = isset($argv[1]) ? $argv[1] : 'asd';
15-
$file = isset($argv[2]) ? $argv[2] : '/etc/passwd';
16-
echo 'Container "' . $container . '" dumping "' . $file . '" (pass as arguments to this example)' . PHP_EOL;
15+
$path = isset($argv[2]) ? $argv[2] : '/etc/passwd';
16+
echo 'Container "' . $container . '" dumping "' . $path . '" (pass as arguments to this example)' . PHP_EOL;
1717

1818
$loop = LoopFactory::create();
1919

2020
$factory = new Factory($loop);
2121
$client = $factory->createClient();
2222

23-
$stream = $client->containerCopyStream($container, array('Resource' => $file));
23+
$stream = $client->containerCopyStream($container, $path);
2424

2525
$tar = new Decoder();
2626

src/Client.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public function containerRemove($container, $v = false, $force = false)
536536
* Copy files or folders of container id
537537
*
538538
* This resolves with a string in the TAR file format containing all files
539-
* specified in the $config array.
539+
* specified in the given $path.
540540
*
541541
* Keep in mind that this means the whole string has to be kept in memory.
542542
* For bigger containers it's usually a better idea to use a streaming approach,
@@ -547,13 +547,13 @@ public function containerRemove($container, $v = false, $force = false)
547547
* work is clue/tar-react (see links).
548548
*
549549
* @param string $container container ID
550-
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
550+
* @param string $resource path to file or directory to copy
551551
* @return PromiseInterface Promise<string> tar stream
552552
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
553553
* @link https://github.com/clue/php-tar-react library clue/tar-react
554554
* @see self::containerCopyStream()
555555
*/
556-
public function containerCopy($container, $config)
556+
public function containerCopy($container, $path)
557557
{
558558
return $this->postJson(
559559
$this->uri->expand(
@@ -562,15 +562,17 @@ public function containerCopy($container, $config)
562562
'container' => $container
563563
)
564564
),
565-
$config
565+
array(
566+
'Resource' => $path
567+
)
566568
)->then(array($this->parser, 'expectPlain'));
567569
}
568570

569571
/**
570572
* Copy files or folders of container id
571573
*
572574
* This returns a stream in the TAR file format containing all files
573-
* specified in the $config array.
575+
* specified in the given $path.
574576
*
575577
* This works for (any number of) files of arbitrary sizes as only small chunks have to
576578
* be kept in memory.
@@ -583,13 +585,13 @@ public function containerCopy($container, $config)
583585
* the normal stream events.
584586
*
585587
* @param string $container container ID
586-
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
588+
* @param string $path path to file or directory to copy
587589
* @return ReadableStreamInterface tar stream
588590
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
589591
* @link https://github.com/clue/php-tar-react library clue/tar-react
590592
* @see self::containerCopy()
591593
*/
592-
public function containerCopyStream($container, $config)
594+
public function containerCopyStream($container, $path)
593595
{
594596
return $this->streamingParser->parsePlainStream(
595597
$this->browser->withOptions(array('streaming' => true))->post(
@@ -602,7 +604,9 @@ public function containerCopyStream($container, $config)
602604
array(
603605
'Content-Type' => 'application/json'
604606
),
605-
$this->json($config)
607+
$this->json(array(
608+
'Resource' => $path
609+
))
606610
)
607611
);
608612
}

0 commit comments

Comments
 (0)