diff --git a/cake/libs/file.php b/cake/libs/file.php index a3872768a93..1b6aed18de4 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -278,6 +278,10 @@ function close() { */ function delete() { clearstatcache(); + if (is_resource($this->handle)) { + fclose($this->handle); + $this->handle = null; + } if ($this->exists()) { return unlink($this->path); } @@ -495,4 +499,4 @@ function &Folder() { return $this->Folder; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 39bc6abc244..db53d74ff2b 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -380,7 +380,7 @@ function testAppend() { function testDelete() { if (!$tmpFile = $this->_getTmpFile()) { return false; - }; + } if (!file_exists($tmpFile)) { touch($tmpFile); @@ -395,6 +395,25 @@ function testDelete() { $result = $TmpFile->delete(); $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()); + } + /** * getTmpFile method * @@ -425,4 +444,4 @@ function _getTmpFile($paintSkip = true) { return false; } } -?> \ No newline at end of file +?>