From 2b9099310738d84f95e0b5d222979d29a0a789e2 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 13 Sep 2023 10:53:21 +0900 Subject: [PATCH] msi: support path which contains space or parenthesis 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 ^"e; 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 --- fluent-package/msi/assets/fluent-gem.bat | 16 ++++++++-------- fluent-package/msi/assets/fluentd.bat | 10 +++++----- fluent-package/msi/source.wxs | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fluent-package/msi/assets/fluent-gem.bat b/fluent-package/msi/assets/fluent-gem.bat index 2f67dd6a7..a050e33d9 100644 --- a/fluent-package/msi/assets/fluent-gem.bat +++ b/fluent-package/msi/assets/fluent-gem.bat @@ -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" %* diff --git a/fluent-package/msi/assets/fluentd.bat b/fluent-package/msi/assets/fluentd.bat index 393ca0b8c..d3ca83a87 100644 --- a/fluent-package/msi/assets/fluentd.bat +++ b/fluent-package/msi/assets/fluentd.bat @@ -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 @@ -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%" diff --git a/fluent-package/msi/source.wxs b/fluent-package/msi/source.wxs index 7bd982642..faeb7f1b7 100644 --- a/fluent-package/msi/source.wxs +++ b/fluent-package/msi/source.wxs @@ -185,7 +185,7 @@ + Value=""[FLUENTPROJECTLOCATION]fluentd.bat" --reg-winsvc i --reg-winsvc-delay-start --reg-winsvc-fluentdopt "-c '[FLUENTPROJECTLOCATION]etc\fluent\fluentd.conf' -o '[FLUENTPROJECTLOCATION]fluentd.log'""/> + Value=""cmd" /c "fsutil hardlink create ^"[FLUENTPROJECTLOCATION]bin\td-agent.bat^" ^"[FLUENTPROJECTLOCATION]fluentd.bat^"""/> + Value=""cmd" /c "fsutil hardlink create ^"[FLUENTPROJECTLOCATION]bin\td-agent-gem.bat^" ^"[FLUENTPROJECTLOCATION]fluent-gem.bat^"""/> + Value=""cmd" /c "del ^"[FLUENTPROJECTLOCATION]bin\td-agent.bat^"""/> + Value=""cmd" /c "del ^"[FLUENTPROJECTLOCATION]bin\td-agent-gem.bat^"""/>