Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlink instead of rmdir links + Cygwin fixes #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.php text
*.json text
*.sh eol=lf
*.bat eol=crlf
3 changes: 2 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target> (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:

Expand Down
61 changes: 38 additions & 23 deletions modman.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -102,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();
}
Expand All @@ -133,6 +149,7 @@ public function printHelp(){
- clean
- create (optional --force, --include <include_file> and --include-hidden)
- clone (optional --force, --create-modman)
- remove (optional --force)

Currently supported in modman-files:
- symlinks (with wildcards)
Expand Down Expand Up @@ -541,7 +558,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();

Expand Down Expand Up @@ -1138,19 +1155,17 @@ private function isFolderEmpty($sDirectoryPath){
* @param string $sElementPath resource to remove
*/
public function doRemoveResource($sElementPath){
if (is_dir($sElementPath)){
if (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);
}
}

/**
Expand Down
25 changes: 25 additions & 0 deletions modman.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/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 [[ `cmd /c ver` =~ Version\ *[6789] ]]
then
if [[ `uname -a` =~ cygwin ]]
then
CYGWIN=`echo "$CYGWIN" | sed -e 's/winsymlinks[:a-z]*//' -e 's/$/ winsymlinks:native/'`
export CYGWIN
fi
fi
}

setupEnv
sScript="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/modman.php";
php "$sScript" "$@";