Skip to content

Commit

Permalink
Merge branch 'w44_MDL-42110_m26_addoninstaller' of https://github.com…
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Oct 28, 2013
2 parents f76bd72 + a635424 commit 9a84376
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
18 changes: 15 additions & 3 deletions admin/tool/installaddon/classes/installer.php
Expand Up @@ -392,8 +392,10 @@ public function download_file($source, $target) {
*
* @param string $source full path to the existing directory
* @param string $target full path to the new location of the directory
* @param int $dirpermissions
* @param int $filepermissions
*/
public function move_directory($source, $target) {
public function move_directory($source, $target, $dirpermissions, $filepermissions) {

if (file_exists($target)) {
throw new tool_installaddon_installer_exception('err_folder_already_exists', array('path' => $target));
Expand All @@ -405,7 +407,16 @@ public function move_directory($source, $target) {
throw new tool_installaddon_installer_exception('err_no_such_folder', array('path' => $source));
}

make_writable_directory($target);
if (!file_exists($target)) {
// Do not use make_writable_directory() here - it is intended for dataroot only.
mkdir($target, true);
@chmod($target, $dirpermissions);
}

if (!is_writable($target)) {
closedir($handle);
throw new tool_installaddon_installer_exception('err_folder_not_writable', array('path' => $target));
}

while ($filename = readdir($handle)) {
$sourcepath = $source.'/'.$filename;
Expand All @@ -416,10 +427,11 @@ public function move_directory($source, $target) {
}

if (is_dir($sourcepath)) {
$this->move_directory($sourcepath, $targetpath);
$this->move_directory($sourcepath, $targetpath, $dirpermissions, $filepermissions);

} else {
rename($sourcepath, $targetpath);
@chmod($targetpath, $filepermissions);
}
}

Expand Down
6 changes: 5 additions & 1 deletion admin/tool/installaddon/deploy.php
Expand Up @@ -69,6 +69,10 @@
get_string('invaliddata', 'core_error'));
}

$installer->move_directory($zipcontentpath.'/'.$pluginname, $plugintypepath.'/'.$pluginname);
// Copy permissions form the plugin type directory.
$dirpermissions = fileperms($plugintypepath);
$filepermissions = ($dirpermissions & 0666); // Strip execute flags.

$installer->move_directory($zipcontentpath.'/'.$pluginname, $plugintypepath.'/'.$pluginname, $dirpermissions, $filepermissions);
fulldelete($CFG->tempdir.'/tool_installaddon/'.$jobid);
redirect(new moodle_url('/admin'));
4 changes: 2 additions & 2 deletions admin/tool/installaddon/tests/installer_test.php
Expand Up @@ -33,7 +33,7 @@
* @copyright 2013 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_installaddon_installer_test extends advanced_testcase {
class tool_installaddon_installer_testcase extends advanced_testcase {

public function test_get_addons_repository_url() {
$installer = testable_tool_installaddon_installer::instance();
Expand Down Expand Up @@ -137,7 +137,7 @@ public function test_move_directory() {
file_put_contents($contentsdir.'/readme.txt', 'Hello world!');

$installer = tool_installaddon_installer::instance();
$installer->move_directory($jobroot.'/contents', $jobroot.'/moved');
$installer->move_directory($jobroot.'/contents', $jobroot.'/moved', 0777, 0666);

$this->assertFalse(is_dir($jobroot.'/contents'));
$this->assertTrue(is_file($jobroot.'/moved/sub/folder/readme.txt'));
Expand Down

0 comments on commit 9a84376

Please sign in to comment.