Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Detect rsync remote connection using colon #288

Merged
merged 4 commits into from

2 participants

@splinter89

I updated FileSyncTask so it can detect remote connection w/o specification of user in destinationDir or sourceDir.
According to rsync manual, they both can be in the following formats: [USER@]HOST:SRC,
[USER@]HOST::SRC,
[USER@]HOST:DEST,
[USER@]HOST::DEST

As we can see, "USER@" part is optional.

@splinter89 splinter89 changed the title from detect rsync remote connection using colon to Detect rsync remote connection using colon
@mrook
Owner

Thanks! Could you update the applicable documentation as well?

@splinter89

I also definitely need help with updating output for docs..

@mrook
Owner

Generating the output is definitely not painless, but I can generate those after the merge. Thanks for the update!

@mrook mrook merged commit 4817868 into phingofficial:master
@splinter89 splinter89 deleted the splinter89:fix-rsync-remote-detection branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2014
  1. @splinter89
Commits on Jun 10, 2014
  1. @splinter89

    update docs

    splinter89 authored
  2. @splinter89

    fix typo

    splinter89 authored
  3. @splinter89

    added some tests

    splinter89 authored
This page is out of date. Refresh to see the latest.
View
8 classes/phing/tasks/ext/FileSyncTask.php
@@ -190,7 +190,7 @@ public function executeCommand()
throw new BuildException('The "destinationdir" attribute is missing or undefined.');
}
- if (strpos($this->destinationDir, '@')) {
+ if (strpos($this->destinationDir, ':')) {
$this->setIsRemoteConnection(true);
} else {
if (! (is_dir($this->destinationDir) && is_readable($this->destinationDir))) {
@@ -198,7 +198,7 @@ public function executeCommand()
}
}
- if (strpos($this->sourceDir, '@')) {
+ if (strpos($this->sourceDir, ':')) {
if ($this->isRemoteConnection) {
throw new BuildException('The source and destination cannot both be remote.');
}
@@ -482,7 +482,7 @@ public function setDryRun($dryRun)
/**
* Requests a simple itemized list of the changes that are being made to each file, including attribute changes.
*
- * @param boolean $dryRun
+ * @param boolean $itemizeChanges
* @return void
*/
public function setItemizeChanges($itemizeChanges)
@@ -536,4 +536,4 @@ public function setIdentityFile($identity)
{
$this->identityFile = $identity;
}
-}
+}
View
19 docs/docbook5/en/source/appendixes/optionaltasks.xml
@@ -1004,16 +1004,19 @@
</tgroup>
</table>
<sect2>
- <title>Example</title>
- <programlisting language="xml">&lt;filesync sourcedir="/var/www/development/project1" destinationdir="/var/www/project1" />;
+ <title>Examples</title>
+ <programlisting language="xml">&lt;filesync sourcedir="/var/www/development/project1" destinationdir="/var/www/project1" />
+
+&lt;filesync sourcedir="host::module" destinationdir="/var/www/project1/" />
&lt;filesync
-sourcedir="/var/www/development/project1"
-destinationdir="user@server:/var/www/project1"
-dryrun="true"
-itemizechanges="true"
-verbose="true"
-checksum="true" />;</programlisting>
+ sourcedir="/var/www/development/project1"
+ destinationdir="user@server:/var/www/project1"
+ dryrun="true"
+ itemizechanges="true"
+ verbose="true"
+ checksum="true" /></programlisting>
+ <para>In the <literal>sourcedir</literal> and <literal>destinationdir</literal> properties user name for remote connections is optional.</para>
</sect2>
</sect1>
<sect1 role="taskdef" xml:id="FtpDeployTask">
View
83 test/classes/phing/tasks/ext/FileSyncTaskTest.php
@@ -0,0 +1,83 @@
+<?php
+/*
+ * $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/BuildFileTest.php';
+require_once '../classes/phing/tasks/ext/FileSyncTask.php';
+
+/**
+ * Tests the FileSync Task
+ *
+ * @author Anton <i.splinter@i.ua>
+ * @version $Id$
+ * @package phing.tasks.ext
+ */
+class FileSyncTaskTest extends BuildFileTest
+{
+ public function setUp()
+ {
+ $this->configureProject(PHING_TEST_BASE
+ . "/etc/tasks/ext/FileSyncTaskTest.xml");
+ $this->executeTarget("setup");
+ }
+
+ public function tearDown()
+ {
+ $this->executeTarget("clean");
+ }
+
+ public function testNoSourceSpecified()
+ {
+ $this->expectBuildExceptionContaining('noSourceDir',
+ 'No source set',
+ '"sourcedir" attribute is missing');
+ }
+
+ public function testNoDestinationSpecified()
+ {
+ $this->expectBuildExceptionContaining('noDestinationDir',
+ 'No destination set',
+ '"destinationdir" attribute is missing');
+ }
+
+ public function testNonexistentSource()
+ {
+ $this->expectBuildExceptionContaining('wrongSource',
+ 'Local source directory must be readable',
+ 'No such file or directory');
+ }
+
+// public function testLocalFileSync()
+// {
+// $this->executeTarget(__FUNCTION__);
+// }
+//
+// public function testRemoteFileSync()
+// {
+// $this->executeTarget(__FUNCTION__);
+// }
+
+ public function testRemoteToRemoteSync()
+ {
+ $this->expectBuildExceptionContaining(__FUNCTION__,
+ 'Either "sourcedir" or "destinationdir" must be local',
+ 'The source and destination cannot both be remote');
+ }
+}
View
42 test/etc/tasks/ext/FileSyncTaskTest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="FileSyncTaskTest" default="main">
+ <property name="tmp.dir" value="tmp"/>
+
+ <target name="setup">
+ <mkdir dir="${tmp.dir}/project"/>
+ </target>
+
+ <target name="clean">
+ <delete dir="${tmp.dir}"/>
+ </target>
+
+ <target name="noSourceDir">
+ <filesync destinationdir="${tmp.dir}/destination/"/>
+ </target>
+
+ <target name="noDestinationDir">
+ <filesync sourcedir="${tmp.dir}/project/"/>
+ </target>
+
+ <target name="wrongSource">
+ <filesync sourcedir="${tmp.dir}/nonexistent/" destinationdir="${tmp.dir}/destination/"/>
+ </target>
+
+ <!--target name="testLocalFileSync">
+ <filesync sourcedir="${tmp.dir}/project/" destinationdir="${tmp.dir}/destination/"/>
+ </target>
+
+ <target name="testRemoteFileSync">
+ <filesync sourcedir="${tmp.dir}/project" destinationdir="host:/var/www/project"/>
+ <filesync sourcedir="${tmp.dir}/project" destinationdir="user@host:/var/www/project"/>
+ <filesync sourcedir="${tmp.dir}/project" destinationdir="host::module"/>
+ <filesync sourcedir="host:/var/www/project" destinationdir="${tmp.dir}/project"/>
+ <filesync sourcedir="user@host:/var/www/remote_project/" destinationdir="${tmp.dir}/project/"/>
+ </target-->
+
+ <target name="testRemoteToRemoteSync">
+ <filesync sourcedir="host1::module" destinationdir="user@host2:/var/www/project"/>
+ </target>
+
+ <target name="main"/>
+</project>
Something went wrong with that request. Please try again.