From 7c9e107a37c1f17795d2c3f4c1b882e67039dcfa Mon Sep 17 00:00:00 2001 From: Russell Robinson Date: Thu, 9 Apr 2015 13:29:01 +1000 Subject: [PATCH 1/4] modman.sh now configures the CYGWIN environment variable so that native Windows symlinks are used. Added missing "remove" command from help. Fix for removing directory links on Cygwin. Added .gitattributes file so that .sh works reliably. --- .gitattributes | 4 ++++ modman.php | 32 ++++++++++++++++++++++++++++++-- modman.sh | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 .gitattributes mode change 100644 => 100755 modman.php mode change 100644 => 100755 modman.sh diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..c2c9a85 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.php text +*.json text +*.sh eol=lf +*.bat eol=crlf \ No newline at end of file diff --git a/modman.php b/modman.php old mode 100644 new mode 100755 index b3bd0d1..2de47ab --- a/modman.php +++ b/modman.php @@ -11,6 +11,27 @@ class Modman { */ const ERR_NO_MODMAN_FILE = 2; + /** + * test if running under Cygwin + * RJR 9-Apr-15 + * + * @return bool true if running on Cygwin, otherwise false + */ + static function isCygWin() { + static $bGotResult = false; // cache the result + static $bIsCygwin; // the result + + if (!$bGotResult) { + if (stripos(php_uname(),'cygwin') !== false) { + $bIsCygwin = true; + } else { + $bIsCygwin = false; + } + $bGotResult = true; + } + return $bIsCygwin; + } + /** * runs and dispatches the modman program * @@ -133,6 +154,7 @@ public function printHelp(){ - clean - create (optional --force, --include and --include-hidden) - clone (optional --force, --create-modman) +- remove (optional --force) Currently supported in modman-files: - symlinks (with wildcards) @@ -541,7 +563,7 @@ public function doDeploy($bForce = false) { if ($this->sModuleName === Modman_Command_Init::MODMAN_BASEDIR_FILE) { return; } - + $oModmanModuleSymlink = new Modman_Module_Symlink($this->sModuleName); $sTarget = $oModmanModuleSymlink->getModmanModuleSymlinkPath(); @@ -1139,7 +1161,13 @@ private function isFolderEmpty($sDirectoryPath){ */ public function doRemoveResource($sElementPath){ if (is_dir($sElementPath)){ - if (is_link($sElementPath) OR $this->isFolderEmpty($sElementPath)){ + // + // I'm not sure why the original logic uses rmdir on a link, but I've kept + // that logic and added the right logic for Cygwin. RJR 9-Apr-15 + // + if (is_link($sElementPath) AND Modman::isCygwin()){ + unlink($sElementPath); + } elseif (is_link($sElementPath) OR $this->isFolderEmpty($sElementPath)){ rmdir($sElementPath); } } else if (is_file($sElementPath)){ diff --git a/modman.sh b/modman.sh old mode 100644 new mode 100755 index bc5d9ce..d296dc6 --- a/modman.sh +++ b/modman.sh @@ -1,4 +1,26 @@ #!/bin/bash +# +# If running under Cygwin, set the type of symlinks we want to use. +# For modman-php we want native NTFS symbolic links. Windows shortcuts +# and Cygwin default symbolic links are not seen by Git or PhpStorm +# and therefore renders modman-php useless in these cases. +# +# Using winsymlinks:native works for me, but according to this thread: +# http:#stackoverflow.com/questions/19780951/cygwin-winsymlinksnative-doesnt-work +# some people may experience problems. Perhaps there are version issues. +# To cover all cases more investigation and additional logic may be needed. +# RJR 9-Apr-15 +# +function setupEnv() { + shopt -s nocasematch + if [[ `uname -a` =~ cygwin ]] + then + CYGWIN=`echo "$CYGWIN" | sed -e 's/winsymlinks[:a-z]*//' -e 's/$/ winsymlinks:native/'` + export CYGWIN + fi +} + +setupEnv sScript="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/modman.php"; php "$sScript" "$@"; From 1c09af75cc55886f2b45ada405ae26ca25ef0e6b Mon Sep 17 00:00:00 2001 From: Russell Robinson Date: Thu, 9 Apr 2015 13:46:32 +1000 Subject: [PATCH 2/4] modman.sh now checks the Windows version before attempting the Cygwin configuration. Added missing "remove" command from README. --- README.md | 3 ++- modman.sh | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7710382..e685c25 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ Currently implemented: - clean (removes all dead symlinks) - create (creates a modman file for an existing module) - clone (clones a git repository) + - remove (removes the symlinks) ---force is available for link, deploy, deploy-all and clone, if not set script aborts when conflicts are found +--force is available for link, deploy, deploy-all, remove and clone, if not set script aborts when conflicts are found Usage examples: diff --git a/modman.sh b/modman.sh index d296dc6..4e2538c 100755 --- a/modman.sh +++ b/modman.sh @@ -14,10 +14,13 @@ # function setupEnv() { shopt -s nocasematch - if [[ `uname -a` =~ cygwin ]] + if [[ `cmd /c ver` =~ Version\ *[6789] ]] then - CYGWIN=`echo "$CYGWIN" | sed -e 's/winsymlinks[:a-z]*//' -e 's/$/ winsymlinks:native/'` - export CYGWIN + if [[ `uname -a` =~ cygwin ]] + then + CYGWIN=`echo "$CYGWIN" | sed -e 's/winsymlinks[:a-z]*//' -e 's/$/ winsymlinks:native/'` + export CYGWIN + fi fi } From 60134d4e03a905826d1fbc740358bf7755c97502 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Sun, 31 May 2015 10:20:14 +0200 Subject: [PATCH 3/4] Files and links should be rm'ed, empty directories should be rmdir'd. --- modman.php | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/modman.php b/modman.php index 2de47ab..b15459b 100755 --- a/modman.php +++ b/modman.php @@ -1160,25 +1160,17 @@ private function isFolderEmpty($sDirectoryPath){ * @param string $sElementPath resource to remove */ public function doRemoveResource($sElementPath){ - if (is_dir($sElementPath)){ - // - // I'm not sure why the original logic uses rmdir on a link, but I've kept - // that logic and added the right logic for Cygwin. RJR 9-Apr-15 - // - if (is_link($sElementPath) AND Modman::isCygwin()){ - unlink($sElementPath); - } elseif (is_link($sElementPath) OR $this->isFolderEmpty($sElementPath)){ - rmdir($sElementPath); - } - } else if (is_file($sElementPath)){ - // workaround for windows to delete read-only flag - // which prevents file from being deleted properly - chmod($sElementPath, 0777); - unlink($sElementPath); - } - elseif (is_link($sElementPath)){ - unlink($sElementPath); - } + + if (is_link($sElementPath)){ + unlink($sElementPath); + } elseif (is_file($sElementPath)) { + // workaround for windows to delete read-only flag + // which prevents file from being deleted properly + chmod($sElementPath, 0777); + unlink($sElementPath); + } elseif ( is_dir($sElementPath) AND $this->isFolderEmpty($sElementPath) ) { + rmdir($sElementPath); + } } /** From 4f4b0c3d9aecb431f626265b0b23c9c141c11300 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Sun, 31 May 2015 10:23:29 +0200 Subject: [PATCH 4/4] Cowsay is a bit too much of a good thing. Doing an external request to decorate a string? --- modman.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/modman.php b/modman.php index b15459b..40cca45 100755 --- a/modman.php +++ b/modman.php @@ -123,15 +123,10 @@ public function run($aParameters) { ) )); $sMessage = $oException->getMessage(); - $sCowsay = @file_get_contents('http://cowsay.morecode.org/say?message=' . urlencode($sMessage) . '&format=text', false, $rCtx); - if ($sCowsay) { - echo $sCowsay; - } else { - echo '-----' . PHP_EOL; - echo 'An error occured:' . PHP_EOL; - echo $sMessage . PHP_EOL; - echo '-----'; - } + echo '-----' . PHP_EOL; + echo 'An error occured:' . PHP_EOL; + echo $sMessage . PHP_EOL; + echo '-----'; echo PHP_EOL . PHP_EOL; $this->printHelp(); }