diff --git a/cake/libs/file.php b/cake/libs/file.php index 972f0726a..13e8fd2f6 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -290,6 +290,10 @@ class File extends Object { */ function delete() { clearstatcache(); + if (is_resource($this->handle)) { + fclose($this->handle); + $this->handle = null; + } if ($this->exists()) { return unlink($this->path); } diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 6e904f9ce..7a7a97d4b 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -395,7 +395,7 @@ class FileTest extends CakeTestCase { function testDelete() { if (!$tmpFile = $this->_getTmpFile()) { return false; - }; + } if (!file_exists($tmpFile)) { touch($tmpFile); @@ -411,6 +411,24 @@ class FileTest extends CakeTestCase { $this->assertFalse($result); } +/** + * Windows has issues unlinking files if there are + * active filehandles open. + * + * @return void + */ + function testDeleteAfterRead() { + if (!$tmpFile = $this->_getTmpFile()) { + return false; + } + if (!file_exists($tmpFile)) { + touch($tmpFile); + } + $file =& new File($tmpFile); + $file->read(); + $this->assertTrue($file->delete()); + } + /** * testCopy method *