Last active
April 25, 2019 09:27
-
-
Save ohader/f4b792e0bb99e79efe75605008ce4a0d to your computer and use it in GitHub Desktop.
Use native symlinks (junction) on Windows host systems (scope: Docker/DDEV environment using TYPO3 & Composer)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem ------------------------------------------------------------------------------------- | |
rem + Scope: Docker/DDEV environment using TYPO3 & Composer | |
rem + to be executed in CMD shell of project root directory | |
rem ------------------------------------------------------------------------------------- | |
rem + This script resolves symbolic links that have been created inside a Linux/Unix | |
rem + environment (and can be resolved there), but should actually be using the system | |
rem + features of their host operating file system. | |
rem ------------------------------------------------------------------------------------- | |
rem + License: MIT | |
rem + Author: Oliver Hader <oliver@typo3.org> | |
rem ------------------------------------------------------------------------------------- | |
setlocal EnableDelayedExpansion | |
for /f "tokens=1 delims=:" %%X in ('findstr /C:"XSym" public\typo3conf\ext\*') do ( | |
set junction=%%X | |
for /f "tokens=* skip=3" %%Y in (!junction!) do ( | |
if not defined targetValue set targetValue=%%Y | |
) | |
for %%Y in (!junction!) do set directory=%%~dpY | |
pushd . | |
cd !directory! | |
call :ResolvePath realPath !targetValue! | |
popd | |
echo ^+ Link [!realPath!] to [!junction!] | |
REM Deleting the existing (regular) file | |
echo ^* deleting file at !junction! | |
del "!junction!" | |
if exist "!junction!" ( | |
echo ^^! failed | |
goto end | |
) | |
REM Creating a new symbolic link using junction | |
echo ^* creating link of !realPath! | |
mklink /D "!junction!" "!realPath!" | |
if not exist "!junction!" ( | |
echo ^^! failed | |
goto end | |
) | |
) | |
if not defined junction echo There is nothing to do... | |
:end | |
endlocal | |
exit /b | |
:ResolvePath | |
set targetValue=%2 | |
set %1=%targetValue:/=\% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ------------------------------------------------------------------------------------- | |
# + Scope: Docker/DDEV environment using TYPO3 & Composer | |
# + to be executed in CMD shell of project root directory | |
# ------------------------------------------------------------------------------------- | |
# + This script resolves symbolic links that have been created inside a Linux/Unix | |
# + environment (and can be resolved there), but should actually be using the system | |
# + features of their host operating file system. | |
# ------------------------------------------------------------------------------------- | |
# + License: MIT | |
# + Author: Oliver Hader <oliver@typo3.org> | |
# ------------------------------------------------------------------------------------- | |
export MSYS=winsymlinks:nativestrict | |
for junction in $(find public/typo3conf/ext/ -maxdepth 1 -not -type d); do | |
match=$(grep -l 'XSym' $junction) | |
if [ "$match" != "$junction" ]; then | |
continue | |
fi | |
realPath="" | |
directory=$(dirname $junction) | |
pointer=$(cat $junction | sed -n 4p) | |
pushd . > /dev/null | |
cd $directory | |
realPath=$(readlink -m $pointer) | |
popd > /dev/null | |
if [ "$realPath" == "" ]; then | |
echo "Could not resolve real path for '$pointer'" | |
exit 1 | |
fi | |
echo "Link [$realPath] to [$junction]" | |
echo " * deleting file at $junction" | |
rm $junction | |
if [ -f $junction ]; then | |
echo " ! failed" | |
exit 1 | |
fi | |
echo " * creating link of $realPath" | |
# cmd /c mklink /J $junction $realPath | |
ln -s $realPath $junction | |
if [ ! -L $junction ]; then | |
echo " ! failed" | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment