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 f91c755cd7b44beb2c5a52c40d1d0c3ebc7da93f 1 parent 0064317
Mark Story markstory authored
Showing with 26 additions and 3 deletions.
  1. +5 −1 cake/libs/file.php
  2. +21 −2 cake/tests/cases/libs/file.test.php
6 cake/libs/file.php
View
@@ -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;
}
}
-?>
+?>
23 cake/tests/cases/libs/file.test.php
View
@@ -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;
}
}
-?>
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.