rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

PAR-Packer (especially "pp") deletes parts of Strawberryperl (portable) Installation when providing "%~f0\.." in a var for TMP/TEMP-Environment #85

Closed vitusb closed 5 months ago

vitusb commented 5 months ago

Hello,

i discovered a strange behaviour of PAR-Packer (pp) script, when using a PATH-extension to portable tools and directories under Strawberryperl's Portable-ROOT-Path (above c\bin... mingw64-suite) in "portableshell.bat". In order to use these paths, i will use a var "EXEDIR", pointing to this Strawberryperl's Portable-ROOT-Path.

Normally that works fine by using...

set drive=%~d0
set drivep=%drive%
If $#\#$==$#%drive:~-1%#$ set drivep=%drive:~0,-1%
set drivename=%drivep%

REM :: relative path to absolute path -PATH-
set pathn=%~p0
set pathp=%pathn%
If $#\#$==$#%pathn:~-1%#$ set pathp=%pathn:~0,-1%
set pathname=%pathp%

set HOMEDRIVE=%drivename%
set HOMEPATH=%pathname%
set EXEDIR=%HOMEDRIVE%%HOMEPATH%

As an example, this will point to:

echo %EXEDIR%
C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable

With a:

set TMP=%EXEDIR%\tmp
set TEMP=%EXEDIR%\tmp

We will have:

TEMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\tmp
TMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\tmp

Everything works fine, but when i change EXEDIR with: "set EXEDIR=%~f0.." to:

EXEDIR=%~f0\..

I will get:

echo %EXEDIR%
C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..  <-----  !!!!

So, with:

set TMP=%EXEDIR%\tmp
set TEMP=%EXEDIR%\tmp

This PATH-reference, i get an environment like: ... TEMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp TMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp ...

Normally that is not a problem, also under a MINGW64 environment, but with an invocation of "pp" under these conditions i will get an error, that an exe-file with a random name unter the temp-dir could not be found or the commandline-prompt hangs (because of deletion-processing in background).

After that error "B.pm", "gcc.exe" inclusive parts of its runtime-helper-binaries under "c\bin..." and other files were deleted.

With a clean PATH for "EXEDIR" without additional "\.." (like my first example above) "pp" works fine.

To reproduce: Simply reference "TEMP" and "TMP" to a construction like:

set TMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp
set TEMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp

Then try to build an exe, but be warned - removal of files begins under STRAWBERRYPERL's ROOT-Dir !! Hit immediately ctrl-c to abort, when you encounter a deletion of "portableshell.bat" or "B.pm", etc.. => pp myexample.pl or pp -o myexample.exe myexample.pl

rschupp commented 5 months ago

set TMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat..\tmp set TEMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat..\tmp

Then try to build an exe, but be warned - removal of files begins under STRAWBERRYPERL's ROOT-Dir !!

Don't do that then.

Seriously, by setting TEMP to a non-existing (even nonsensical) path, all bets are off.

The only recursive file removal in pp is in script/par.pl starting on line 194.

vitusb commented 5 months ago

Seriously, by setting TEMP to a non-existing (even nonsensical) path, all bets are off.

Okay, but the "path" is existent and due to batch-scripting-logic under windows' "cmd.exe - environment" it is legit to use this awfull mechanism 😸 ...

For example:

C:\Temp>echo.@echo Var01: %~f0 >test.bat
C:\Temp>echo.@echo Var02: %~dp0 >>test.bat
C:\Temp>test.bat
Var01: C:\Temp\test.bat
Var02: C:\Temp\

The expression "%~f0\..\" is sometimes used, when running or finding some stuff from Windows Server-Shares \\servername\SHARE\.

But you're right ... it is better to use the "%~dp0" - mechanism for referencing objects under "portable conditions" like strawberryperl portable 😄 .

rschupp commented 5 months ago

FWIW: I can't reproduce your problem. I installed Strawberry Portable in the same path as you and upgraded PAR and PAR::Packer to their latest versions. Then

set TMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp
set TEMP=C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable\portableshell.bat\..\tmp
pp -o hello.exe -E "say 'hello'"

All files under C:\Temp\Perl\strawberry-perl-5.38.2.2-64bit-portable (checked against the downloaded zip) are accounterd for.

vitusb commented 5 months ago

Okay, maybe it's an issue with the environment ... I see, you're using some external tools (i. e. rm, etc. ...); i'm using in my search-path for example busybox for some shell-applet emulations. I already discovered bad side-effects, using old msys 1.0 and busybox shell-tools with incompatible parameters, etc., when executing other Makefiles. Maybe that could be the reason for this issue (plus bad masking of path-separation and so on).

I wil not investigate this further ... Thanx for your support.