Skip to content

Commit

Permalink
msi: refactor execution bat files
Browse files Browse the repository at this point in the history
* Add entire local scope to prevent changing global env vars
* Remove unnecessary enabledelayedexpansion
* Remove unnecessary `/`

Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
daipom authored and kenhys committed Jun 27, 2024
1 parent 02db3f5 commit efb8897
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions fluent-package/msi/assets/fluent-gem.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@echo off
setlocal

if "%~nx0" == "td-agent-gem.bat" (
set "FLUENT_PACKAGE_TOPDIR=%~dp0..\"
) else (
Expand All @@ -10,3 +12,5 @@ for /f "usebackq" %%i in (`^""%FLUENT_PACKAGE_BINDIR%\ruby.exe" -rrbconfig -e "p
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" %*

endlocal
18 changes: 12 additions & 6 deletions fluent-package/msi/assets/fluentd.bat
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
@echo off
setlocal

if "%~nx0" == "td-agent.bat" (
set "FLUENT_PACKAGE_TOPDIR=%~dp0..\"
) else (
set "FLUENT_PACKAGE_TOPDIR=%~dp0"
)

@rem Convert path separator from backslash to forwardslash
setlocal enabledelayedexpansion
set FLUENT_PACKAGE_TOPDIR=!FLUENT_PACKAGE_TOPDIR:\=/!
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"

setlocal
set "FLUENT_PACKAGE_VERSION=%FLUENT_PACKAGE_TOPDIR%bin/fluent-package-version.rb"
for %%p in (%*) do (
if "%%p"=="--version" (
ruby "%FLUENT_PACKAGE_VERSION%"
goto last
)
)
"%FLUENT_PACKAGE_TOPDIR%/bin/fluentd" %*
endlocal

"%FLUENT_PACKAGE_TOPDIR%bin/fluentd" %*

endlocal

:last

0 comments on commit efb8897

Please sign in to comment.