title: Is there an ant task that can copy without losing permissions
body: <p>I'm aware that I can <code>&lt;exec executable="cp" failonerror="true"&gt;</code>, however, I'd really rather have a task that I can call from any OS that can use all (or at least most) of the attributes to <code>copy</code>, but which doesn't suck away the permissions on unix.</p>
  
  <p>I am wondering if there is already a solution out there, or will I have to write my own <code>copy2</code>.</p>
  
  <p>As I was kind of afraid, there's nothing "off the shelf".  We have this code, but it only handles directory to directory copy or file to file copy, has custom attributes, and doesn't do any of the other neat things copy does.</p>
  
  <pre><code>&lt;!-- ==================================================================== --&gt;
  &lt;!-- Copy files from A to B                                               --&gt;
  &lt;!-- &lt;copy&gt; would do this job, if it weren't such a useless pile of fail  --&gt;
  &lt;!-- and could manage to preserve execute bits on Linux                   --&gt;
  &lt;!-- ==================================================================== --&gt;
  &lt;macrodef name="internal-copydir"&gt;
      &lt;attribute name="fromdir" default="NOT SET" /&gt;
      &lt;attribute name="todir" default="NOT SET" /&gt;
      &lt;sequential&gt;
          &lt;if&gt;
              &lt;os family="windows" /&gt;
              &lt;then&gt;
                  &lt;copy todir="@{todir}"&gt;
                      &lt;fileset dir="@{fromdir}" /&gt;
                  &lt;/copy&gt;
              &lt;/then&gt;
              &lt;else&gt;
                  &lt;exec executable="rsync" failonerror="true"&gt;
                      &lt;arg value="-a" /&gt;
                      &lt;arg value="@{fromdir}/" /&gt;
                      &lt;arg value="@{todir}/" /&gt;
                  &lt;/exec&gt;
              &lt;/else&gt;
          &lt;/if&gt;
      &lt;/sequential&gt;
  &lt;/macrodef&gt;
  
  &lt;!-- ==================================================================== --&gt;
  &lt;!-- Copy file from A to B                                                --&gt;
  &lt;!-- &lt;copy&gt; would do this job, if it weren't such a useless pile of fail  --&gt;
  &lt;!-- and could manage to preserve execute bits on Linux                   --&gt;
  &lt;!-- ==================================================================== --&gt;
  &lt;macrodef name="internal-copyfile"&gt;
      &lt;attribute name="file" default="NOT SET" /&gt;
      &lt;attribute name="tofile" default="NOT SET" /&gt;
      &lt;sequential&gt;
          &lt;if&gt;
              &lt;os family="windows" /&gt;
              &lt;then&gt;
                  &lt;copy file="@{file}" tofile="@{tofile}"/&gt;
              &lt;/then&gt;
              &lt;else&gt;
                  &lt;exec executable="cp" failonerror="true"&gt;
                      &lt;arg value="@{file}" /&gt;
                      &lt;arg value="@{tofile}" /&gt;
                  &lt;/exec&gt;
              &lt;/else&gt;
          &lt;/if&gt;
      &lt;/sequential&gt;
  &lt;/macrodef&gt;
  </code></pre>
  
  <p>I wrote this one too.</p>
  
  <pre><code>&lt;!-- ==================================================================== --&gt;
  &lt;!-- Copy file to a directory                                             --&gt;
  &lt;!-- &lt;copy&gt; would do this job, if it weren't such a useless pile of fail  --&gt;
  &lt;!-- and could manage to preserve execute bits on Linux                   --&gt;
  &lt;!-- ==================================================================== --&gt;
  &lt;macrodef name="internal-copyfiletodir"&gt;
      &lt;attribute name="file" default="NOT SET" /&gt;
      &lt;attribute name="todir" default="NOT SET" /&gt;
      &lt;sequential&gt;
          &lt;if&gt;
              &lt;os family="windows" /&gt;
              &lt;then&gt;
                  &lt;copy file="@{file}" todir="@{todir}"/&gt;
              &lt;/then&gt;
              &lt;else&gt;
                  &lt;exec executable="cp" failonerror="true"&gt;
                      &lt;arg value="@{file}" /&gt;
                      &lt;arg value="@{todir}/" /&gt;
                  &lt;/exec&gt;
              &lt;/else&gt;
          &lt;/if&gt;
      &lt;/sequential&gt;
  &lt;/macrodef&gt;
  </code></pre>