Exports added by :with are ineffective when :user is specified
まだ誰も着手していません。
評価
調査の方向性
まず、issue に示されている with および user の builder メソッドを見つけ、両方のオプションを使用した場合に、生成される shell コマンドをどのように組み立てているかを確認します。with builder がユーザーコマンドに対して export サブシェルを追加せず、user builder が引き続き環境変数を提供すれば、変更は完了です。
索引モデルが issue の本文から書いたものです。
説明
When a command is mapped, (:should_map?), both :with and :user are invoked.
In both builder methods, the environment variables specified are intended to be inherited by the subshell.
Say that we have the env var MYVAR=myvar, and the command mycommand, which needs to be run as the user myuser. The relevant builder methods are:
def with(&_block)
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
def user(&_block)
return yield unless options[:user]
env_string = environment_string
"sudo -u #{options[:user].to_s.shellescape} #{env_string + " " unless env_string.empty?}-- sh -c #{yield.shellescape}"
end
this will generate something like:
( export MYVAR=myvar ; sudo -u myuser MYVAR=myvar -- sh -c command )
The problem is that the export is ineffective, because exports are not inherited by the sudo subshell.
While this is harmless, it clutters the generated commands, and it's also semantically incorrect (because it's ineffective) and confusing.
This could be avoided by just yielding the the builder block if options[:user] is set:
def with(&_block)
> # Exports are ineffective on non-login (sudo) shells; in this case, the :user builder takes
> # care of setting them.
> return yield if options[:user]
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
This makes the (internal) commands output more readable (and understandable). While this has no effect on the end users, it helps understanding those who approach Capistrano/Sshkit development (at least, it did it for me 😬).
If this is approved (either in this form or another), I can easily open a PR.
- 主要言語
- Ruby
- スター
- 1.2k
- フォーク
- 257
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
capistrano/sshkit のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
capistrano/sshkit#563 · リアクション 6 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
capistrano/sshkit#562 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
capistrano/sshkit#554 · コメント 3 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
capistrano/sshkit#543 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
capistrano/sshkit#518 · コメント 1 件 ·
capistrano/sshkit の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
riscv/riscv-unified-db#2626 ·
-
Component: GLib
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
ds-drift
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
we-promise/sure#3693 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
simp/pupmod-simp-simp#395 ·