Skip to content
Snippets Groups Projects
Commit c4d13987 authored by dame's avatar dame Committed by Rajab Natshah
Browse files

Issue #2973026 by dame: Replaced exec in remove Git Repositories with Symfony...

Issue #2973026 by dame: Replaced exec in remove Git Repositories with Symfony Finder & File System to work with Windows and Linux
parent 37caf40e
No related branches found
No related tags found
No related merge requests found
......@@ -109,7 +109,12 @@ class ScriptHandler {
*/
public static function removeGitDirectories() {
$drupal_root = static::getDrupalRoot(getcwd());
exec("find " . $drupal_root . " -name '.git' | xargs rm -rf");
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
self::removeWindowsGitDirectories($drupal_root);
} else {
exec("find " . $drupal_root . " -name '.git' | xargs rm -rf");
}
}
/**
......@@ -151,4 +156,43 @@ class ScriptHandler {
}
}
/**
* Find and return the path to .git repository in root folder
* @param string $root
*/
private static function removeWindowsGitDirectories($root) {
foreach (scandir($root) as $dirOrFile) {
if ('.' === $dirOrFile || '..' === $dirOrFile ) {
continue;
}
if ('.git' === $dirOrFile){
self::rmdirWindows($root.'/.git');
} elseif(!is_file($root.'/'.$dirOrFile)) {
self::removeWindowsGitDirectories($root.'/'.$dirOrFile);
}
}
}
/**
* Remove a directory on Windows
* @param string $dirname
*/
private static function rmdirWindows($dirname) {
if (is_file($dirname)) {
unlink($dirname);
return;
}
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
if ($entry === '.' || $entry === '..') {
continue;
}
self::rmdirWindows("$dirname/$entry");
}
$dir->close();
rmdir($dirname);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment