Made it possible to ignore build files when exporting development folders.

pull/27/head
thomasmars 2016-09-23 15:46:52 +02:00
parent 1c5b9707e5
commit cee88a544f
1 changed files with 22 additions and 1 deletions

View File

@ -275,6 +275,8 @@ class H5PDefaultStorage implements \H5PFileStorage {
throw new \Exception('unabletocopy');
}
$ignoredFiles = self::getIgnoredFiles("{$source}/.h5pignore");
$dir = opendir($source);
if ($dir === FALSE) {
trigger_error('Unable to open directory ' . $source, E_USER_WARNING);
@ -282,7 +284,7 @@ class H5PDefaultStorage implements \H5PFileStorage {
}
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') {
if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore' && !in_array($file, $ignoredFiles)) {
if (is_dir("{$source}/{$file}")) {
self::copyFileTree("{$source}/{$file}", "{$destination}/{$file}");
}
@ -294,6 +296,25 @@ class H5PDefaultStorage implements \H5PFileStorage {
closedir($dir);
}
/**
* Retrieve array of file names from file.
*
* @param string $file
* @return array Array with files that should be ignored
*/
private static function getIgnoredFiles($file) {
if (file_exists($file) === FALSE) {
return array();
}
$contents = file_get_contents($file);
if ($contents === FALSE) {
return array();
}
return preg_split('/\s+/', $contents);
}
/**
* Recursive function that makes sure the specified directory exists and
* is writable.