Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(TB FS) properly delete temp files in copyTempfile
Browse files Browse the repository at this point in the history
Change-Id: I4b3d5ecdbbe8507b3af6a469a531d4437f31c5f6
Reviewed-on: http://gerrit.tine20.com/customers/18525
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
  • Loading branch information
paulmhh committed Dec 1, 2020
1 parent f6c93ae commit 3e48351
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/tine20/Filemanager/Frontend/JsonTests.php
Expand Up @@ -98,6 +98,8 @@ protected function setUp(): void
Tinebase_Container::getInstance()->getDefaultContainer('Filemanager_Model_Node');

$this->_createdNodesJson = null;

copy(dirname(dirname(__FILE__)) . '/files/test.txt', dirname(dirname(__FILE__)) . '/files/test.txt.bkp');
}

/**
Expand Down Expand Up @@ -130,6 +132,13 @@ protected function tearDown(): void
$this->_personalContainer = null;
$this->_sharedContainer = null;
$this->_otherUserContainer = null;

clearstatcache();
if (!is_file(dirname(dirname(__FILE__)) . '/files/test.txt')) {
rename(dirname(dirname(__FILE__)) . '/files/test.txt.bkp', dirname(dirname(__FILE__)) . '/files/test.txt');
} else {
unlink(dirname(dirname(__FILE__)) . '/files/test.txt.bkp');
}
}

/**
Expand Down Expand Up @@ -982,6 +991,7 @@ public function testCreateFileNodeWithTempfile()

$this->assertEquals('text/plain', $result['contenttype'], print_r($result, true));
$this->assertEquals(17, $result['size']);
$this->assertFalse(is_file(dirname(dirname(__FILE__)) . '/files/test.txt'));

return $result;
}
Expand Down
4 changes: 2 additions & 2 deletions tine20/Tinebase/FileSystem.php
Expand Up @@ -2851,15 +2851,15 @@ public function copyTempfile($tempFile, &$path, $deleteTempFileAfterCopy = false
$tempStream = $tempFile;
} else if (is_string($tempFile) || is_array($tempFile)) {
$tempFile = Tinebase_TempFile::getInstance()->getTempFile($tempFile);
return $this->copyTempfile($tempFile, $path);
return $this->copyTempfile($tempFile, $path, $deleteTempFileAfterCopy);
} else if ($tempFile instanceof Tinebase_Model_Tree_Node) {
if (isset($tempFile->hash)) {
$hashFile = $this->getRealPathForHash($tempFile->hash);
$tempStream = fopen($hashFile, 'r');
} else if (is_resource($tempFile->stream)) {
$tempStream = $tempFile->stream;
} else {
return $this->copyTempfile($tempFile->tempFile, $path);
return $this->copyTempfile($tempFile->tempFile, $path, $deleteTempFileAfterCopy);
}
} else if ($tempFile instanceof Tinebase_Model_TempFile) {
$tempStream = fopen($tempFile->path, 'r');
Expand Down

0 comments on commit 3e48351

Please sign in to comment.