function hackedProjectWebFilesDownloader::archive_extract in Hacked! 7.2
Unpack a downloaded archive file.
Parameters
string $project: The short name of the project to download.
string $file: The filename of the archive you wish to extract.
string $directory: The directory you wish to extract the archive into.
Return value
Archiver The Archiver object used to extract the archive.
Throws
Exception on failure.
1 call to hackedProjectWebFilesDownloader::archive_extract()
- hackedProjectWebFilesDownloader::download in includes/
hackedProjectWebFilesDownloader.inc - Download the remote files to the local filesystem.
File
- includes/
hackedProjectWebFilesDownloader.inc, line 103
Class
- hackedProjectWebFilesDownloader
- Downloads a project using a standard Drupal method.
Code
function archive_extract($file, $directory) {
$archiver = archiver_get_archiver($file);
if (!$archiver) {
throw new Exception(t('Cannot extract %file, not a valid archive.', array(
'%file' => $file,
)));
}
// Remove the directory if it exists, otherwise it might contain a mixture of
// old files mixed with the new files (e.g. in cases where files were removed
// from a later release).
$files = $archiver
->listContents();
// Unfortunately, we can only use the directory name for this. :(
$project = drupal_substr($files[0], 0, -1);
$extract_location = $directory . '/' . $project;
if (file_exists($extract_location)) {
file_unmanaged_delete_recursive($extract_location);
}
$archiver
->extract($directory);
return $archiver;
}