Skip to content

Commit

Permalink
Fixes #981 - don't touch symlinks when preserveLastModified is true
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Mar 28, 2013
1 parent 964b7b4 commit 66317a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/phing/util/FileUtils.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function copyFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite = false
} }
} }


if ($preserveLastModified) { if ($preserveLastModified && !$destFile->isLink()) {
$destFile->setLastModified($sourceFile->lastModified()); $destFile->setLastModified($sourceFile->lastModified());
} }


Expand Down
16 changes: 16 additions & 0 deletions test/classes/phing/tasks/system/CopyTaskTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,5 +51,21 @@ public function testCopyDanglingSymlink()
$this->executeTarget("testCopyDanglingSymlink"); $this->executeTarget("testCopyDanglingSymlink");
$this->assertInLogs("Copying 1 file to"); $this->assertInLogs("Copying 1 file to");
} }

/**
* Test for {@link http://www.phing.info/trac/ticket/981}
* FileUtil::copyFile(): preserveLastModified causes
* empty symlink target file
*/
public function testCopySymlinkPreserveLastModifiedShouldCopyTarget()
{
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$this->markTestSkipped("Bug not applicable on Window");
}

$this->executeTarget(__FUNCTION__);
$this->assertInLogs("Copying 2 files to");
$this->assertGreaterThan(0, $this->project->getProperty('test.filesize'));
}
} }


16 changes: 16 additions & 0 deletions test/etc/tasks/system/CopyTaskTest.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@
<delete dir="${tmp.dir}/new"/> <delete dir="${tmp.dir}/new"/>
</target> </target>


<target name="testCopySymlinkPreserveLastModifiedShouldCopyTarget">
<mkdir dir="${tmp.dir}/base"/>
<mkdir dir="${tmp.dir}/new"/>
<echo file="${tmp.dir}/base/x" message="Testmessage"/>
<symlink target="x" link="${tmp.dir}/base/y"/>

<copy todir="${tmp.dir}/new" preserveLastModified="true">
<filelist dir="${tmp.dir}/base" files="y,x"/>
</copy>

<filesize file="${tmp.dir}/new/x" propertyname="test.filesize"/>

<delete dir="${tmp.dir}/base"/>
<delete dir="${tmp.dir}/new"/>
</target>

<target name="main"/> <target name="main"/>
</project> </project>

0 comments on commit 66317a6

Please sign in to comment.