Skip to content

Commit

Permalink
add check if uncompresseddir is valid
Browse files Browse the repository at this point in the history
I removed the deletion of $tempdir content. I needed a clean directory to unpack the plugin to avoid finding the wrong version.php file. I instead create a subdirectory for this purpose.

I thought clearing the $tempdir wouldn't be a problem since the downloaded content was removed after being unpacked anyway.

the check for the validity of uncompresseddir is added
  • Loading branch information
montanae authored and tmuras committed May 30, 2024
1 parent fe7f720 commit 5d1e9ec
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Moosh/Command/Generic/Plugin/PluginInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public function execute()

if (!file_exists($tempdir)) {
mkdir($tempdir);
} else {
run_external_command("rm -rf $tempdir/*");
}

if (!fopen($downloadedfile, 'w')) {
Expand Down Expand Up @@ -98,12 +96,22 @@ public function execute()
}
}

run_external_command("unzip $downloadedfile -d $tempdir");
$unzipdir = $tempdir . $component;
if (!file_exists($unzipdir)) {
mkdir($unzipdir);
}

run_external_command("unzip $downloadedfile -d $unzipdir");
run_external_command("rm $downloadedfile");

//Get the path of uncompressed plugin dir (in case the .zip decompresses into multiple directories / non standard directory)
$uncompresseddir = exec("find $tempdir -name 'version.php' | rev | cut -d'/' -f 2- | rev");
run_external_command("mv $uncompresseddir $targetpath");
$uncompresseddir = exec("find $unzipdir -name 'version.php' | rev | cut -d'/' -f 2- | rev");
if (file_exists($uncompresseddir)){
run_external_command("mv $uncompresseddir $targetpath");
} else {
die("The zipfile does not seem to be a valid plugin (no version.php found)\n");
}
run_external_command("rm -rf $unzipdir");

echo "Installing\n";
echo "\tname: $pluginname\n";
Expand Down

0 comments on commit 5d1e9ec

Please sign in to comment.