From 2741a58bf9486212f012a91eb8a32d34422e7fc7 Mon Sep 17 00:00:00 2001 From: Siad Ardroumli Date: Sat, 22 Feb 2020 14:52:54 +0100 Subject: [PATCH 1/2] [FileUtils] Added granularity support Added granularity support for copyFile (the number of seconds leeway to give before deciding a file is out of date). --- classes/phing/util/FileUtils.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/phing/util/FileUtils.php b/classes/phing/util/FileUtils.php index fca95630bd..3aac0149a0 100644 --- a/classes/phing/util/FileUtils.php +++ b/classes/phing/util/FileUtils.php @@ -111,6 +111,7 @@ public static function getChainedReader(Reader $in, &$filterChains, Project $pro * @param Project $project * @param integer $mode * @param bool $preservePermissions + * @param int $granularity * @throws Exception * @throws IOException * @return void @@ -123,9 +124,14 @@ public function copyFile( $preserveLastModified = true, &$filterChains = null, $mode = 0755, - $preservePermissions = true + $preservePermissions = true, + int $granularity = 0 ) { - if ($overwrite || !$destFile->exists() || $destFile->lastModified() < $sourceFile->lastModified()) { + if ( + $overwrite + || !$destFile->exists() + || $destFile->lastModified() < $sourceFile->lastModified() - $granularity + ) { if ($destFile->exists() && ($destFile->isFile() || $destFile->isLink())) { $destFile->delete(); } From 067e248d5e32eb5586c3065faa6c0f5e11195576 Mon Sep 17 00:00:00 2001 From: Siad Ardroumli Date: Sat, 22 Feb 2020 15:34:19 +0100 Subject: [PATCH 2/2] Added test --- test/classes/phing/util/FileUtilsTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/classes/phing/util/FileUtilsTest.php b/test/classes/phing/util/FileUtilsTest.php index 6fffdada26..1a13f41aa4 100644 --- a/test/classes/phing/util/FileUtilsTest.php +++ b/test/classes/phing/util/FileUtilsTest.php @@ -54,4 +54,17 @@ public function contentEquals() $this->assertFalse($this->fu->contentEquals(new PhingFile(__DIR__), new PhingFile(__FILE__))); $this->assertTrue($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile(__FILE__))); } + + /** + * @test + */ + public function copyFile() + { + $this->fu->copyFile(new PhingFile(__FILE__), new PhingFile('tmp/test.php'), $this->getProject()); + try { + $this->assertFileExists('tmp/test.php'); + } finally { + @unlink('tmp/test.php'); + } + } }