Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing file deletion issue in windows

where unlink() cannot delete files that have open
file handles.
Fixes #376
  • Loading branch information...
commit ff0119ba6f4fb95249ab00616c7d9d67477fb550 1 parent 5b43d6b
@markstory markstory authored
Showing with 23 additions and 1 deletion.
  1. +4 −0 cake/libs/file.php
  2. +19 −1 cake/tests/cases/libs/file.test.php
View
4 cake/libs/file.php
@@ -290,6 +290,10 @@ function close() {
*/
function delete() {
clearstatcache();
+ if (is_resource($this->handle)) {
+ fclose($this->handle);
+ $this->handle = null;
+ }
if ($this->exists()) {
return unlink($this->path);
}
View
20 cake/tests/cases/libs/file.test.php
@@ -395,7 +395,7 @@ function testAppend() {
function testDelete() {
if (!$tmpFile = $this->_getTmpFile()) {
return false;
- };
+ }
if (!file_exists($tmpFile)) {
touch($tmpFile);
@@ -412,6 +412,24 @@ function testDelete() {
}
/**
+ * 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
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.