Skip to content

Commit

Permalink
msi: support path which contains space or parenthesis (#589)
Browse files Browse the repository at this point in the history
When installing fluent-package to c:\Program Files, the space
character must be escaped correctly.

* sources.wxs
  * For xml, double quote (") must be "
  * to escape double quote in literal, you must escape with ^&quote;
    it is treated as ^", so it is properly quoted to execute:

  "cmd" /c "fsutil ... "c:\Program Files .." "c:\Program Files...""

* fluentd.bat,fluent-gem.bat
  * set FOO="..." assign extra double quote, it's troublesome because
  extra double quote will be included when concatenating path.
  The only way to avoid this problem is set "FOO=..." to assign it.
  you can assign to FOO without extra double quote.
  * to get RUBY_VERSION, use "usebackq" and execute command with
    escaped command literal explicitly.
     passed `^""C:\..." ....^"` literal are evaluated ^""C:\..."^".

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys authored Sep 27, 2023
1 parent 2964ab2 commit b4b7017
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions fluent-package/msi/assets/fluent-gem.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@echo off
if "%~nx0" == "td-agent-gem.bat" (
set FLUENT_PACKAGE_TOPDIR=%~dp0..\
set "FLUENT_PACKAGE_TOPDIR=%~dp0..\"
) else (
set FLUENT_PACKAGE_TOPDIR=%~dp0
set "FLUENT_PACKAGE_TOPDIR=%~dp0"
)
set FLUENT_PACKAGE_BINDIR=%FLUENT_PACKAGE_TOPDIR%bin
set PATH="%FLUENT_PACKAGE_BINDIR%";%PATH%
for /f "usebackq" %%i in (`%FLUENT_PACKAGE_BINDIR%\ruby.exe -rrbconfig -e "print RbConfig::CONFIG['ruby_version']"`) do set RUBY_VERSION=%%i
set GEM_HOME=%FLUENT_PACKAGE_TOPDIR%lib\ruby\gems\%RUBY_VERSION%
set GEM_PATH=%FLUENT_PACKAGE_TOPDIR%lib\ruby\gems\%RUBY_VERSION%
%FLUENT_PACKAGE_BINDIR%\fluent-gem %*
set "FLUENT_PACKAGE_BINDIR=%FLUENT_PACKAGE_TOPDIR%bin"
set PATH=%FLUENT_PACKAGE_BINDIR%;%PATH%
for /f "usebackq" %%i in (`^""%FLUENT_PACKAGE_BINDIR%\ruby.exe" -rrbconfig -e "print RbConfig::CONFIG['ruby_version']"^"`) do set RUBY_VERSION=%%i
set "GEM_HOME=%FLUENT_PACKAGE_TOPDIR%lib\ruby\gems\%RUBY_VERSION%"
set "GEM_PATH=%FLUENT_PACKAGE_TOPDIR%lib\ruby\gems\%RUBY_VERSION%"
"%FLUENT_PACKAGE_BINDIR%\fluent-gem" %*
10 changes: 5 additions & 5 deletions fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@echo off
if "%~nx0" == "td-agent.bat" (
set FLUENT_PACKAGE_TOPDIR=%~dp0..\
set "FLUENT_PACKAGE_TOPDIR=%~dp0..\"
) else (
set FLUENT_PACKAGE_TOPDIR=%~dp0
set "FLUENT_PACKAGE_TOPDIR=%~dp0"
)

@rem Convert path separator from backslash to forwardslash
Expand All @@ -11,9 +11,9 @@ set FLUENT_PACKAGE_TOPDIR=!FLUENT_PACKAGE_TOPDIR:\=/!

set PATH=%FLUENT_PACKAGE_TOPDIR%bin;%PATH%
set PATH=%FLUENT_PACKAGE_TOPDIR%;%PATH%
set FLUENT_CONF=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/fluentd.conf
set FLUENT_PLUGIN=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/plugin
set FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%/bin/fluent-package-version.rb
set "FLUENT_CONF=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/fluentd.conf"
set "FLUENT_PLUGIN=%FLUENT_PACKAGE_TOPDIR%/etc/fluent/plugin"
set "FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%/bin/fluent-package-version.rb"
for %%p in (%*) do (
if "%%p"=="--version" (
ruby "%FLUENT_PACKAGE_VERSION%"
Expand Down
10 changes: 5 additions & 5 deletions fluent-package/msi/source.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<Property Id="InstallFluentdWinSvc" Value=" "/>
<CustomAction Id="SetInstallFluentdWinSvcCommand"
Property="InstallFluentdWinSvc"
Value="&quot;[FLUENTPROJECTLOCATION]fluentd.bat&quot; --reg-winsvc i --reg-winsvc-delay-start --reg-winsvc-fluentdopt &quot;-c [FLUENTPROJECTLOCATION]etc\fluent\fluentd.conf -o [FLUENTPROJECTLOCATION]fluentd.log&quot;"/>
Value="&quot;[FLUENTPROJECTLOCATION]fluentd.bat&quot; --reg-winsvc i --reg-winsvc-delay-start --reg-winsvc-fluentdopt &quot;-c '[FLUENTPROJECTLOCATION]etc\fluent\fluentd.conf' -o '[FLUENTPROJECTLOCATION]fluentd.log'&quot;"/>
<CustomAction Id="InstallFluentdWinSvc"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Expand All @@ -196,7 +196,7 @@
<Property Id="CreateCompatTdAgentBat" Value=" "/>
<CustomAction Id="SetCreateCompatTdAgentBat"
Property="CreateCompatTdAgentBat"
Value="&quot;cmd&quot; /c &quot;fsutil hardlink create [FLUENTPROJECTLOCATION]bin\td-agent.bat [FLUENTPROJECTLOCATION]fluentd.bat&quot;"/>
Value="&quot;cmd&quot; /c &quot;fsutil hardlink create ^&quot;[FLUENTPROJECTLOCATION]bin\td-agent.bat^&quot; ^&quot;[FLUENTPROJECTLOCATION]fluentd.bat^&quot;&quot;"/>
<CustomAction Id="CreateCompatTdAgentBat"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Expand All @@ -206,7 +206,7 @@
<Property Id="CreateCompatTdAgentGemBat" Value=" "/>
<CustomAction Id="SetCreateCompatTdAgentGemBat"
Property="CreateCompatTdAgentGemBat"
Value="&quot;cmd&quot; /c &quot;fsutil hardlink create [FLUENTPROJECTLOCATION]bin\td-agent-gem.bat [FLUENTPROJECTLOCATION]fluent-gem.bat&quot;"/>
Value="&quot;cmd&quot; /c &quot;fsutil hardlink create ^&quot;[FLUENTPROJECTLOCATION]bin\td-agent-gem.bat^&quot; ^&quot;[FLUENTPROJECTLOCATION]fluent-gem.bat^&quot;&quot;"/>
<CustomAction Id="CreateCompatTdAgentGemBat"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Expand All @@ -217,7 +217,7 @@
<Property Id="DeleteCompatTdAgentBat" Value=" "/>
<CustomAction Id="SetDeleteCompatTdAgentBat"
Property="DeleteCompatTdAgentBat"
Value="&quot;cmd&quot; /c &quot;del [FLUENTPROJECTLOCATION]bin\td-agent.bat&quot;"/>
Value="&quot;cmd&quot; /c &quot;del ^&quot;[FLUENTPROJECTLOCATION]bin\td-agent.bat^&quot;&quot;"/>
<CustomAction Id="DeleteCompatTdAgentBat"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Expand All @@ -227,7 +227,7 @@
<Property Id="DeleteCompatTdAgentGemBat" Value=" "/>
<CustomAction Id="SetDeleteCompatTdAgentGemBat"
Property="DeleteCompatTdAgentGemBat"
Value="&quot;cmd&quot; /c &quot;del [FLUENTPROJECTLOCATION]bin\td-agent-gem.bat&quot;"/>
Value="&quot;cmd&quot; /c &quot;del ^&quot;[FLUENTPROJECTLOCATION]bin\td-agent-gem.bat^&quot;&quot;"/>
<CustomAction Id="DeleteCompatTdAgentGemBat"
BinaryKey="WixCA"
DllEntry="WixQuietExec64"
Expand Down

0 comments on commit b4b7017

Please sign in to comment.