mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing file deletion issue in windows
where unlink() cannot delete files that have open file handles. Fixes #376
This commit is contained in:
parent
5b43d6b9a7
commit
ff0119ba6f
2 changed files with 23 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue