Signed-off-by: Cao Xueliang caoxl78320@163.com --- src/lib/job.cr | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/lib/job.cr b/src/lib/job.cr index 218e2e1..1c6eb1a 100644 --- a/src/lib/job.cr +++ b/src/lib/job.cr @@ -249,10 +249,37 @@ class Job set_upload_dirs() end
+ def get_pkg_common_dir + common_dir = "" + + if @hash["cci-makepkg"]? + pkg_style = "cci-makepkg" + elsif @hash["cci-depends"]? + pkg_style = "cci-depends" + elsif @hash["build-pkg"]? + pkg_style = "build-pkg" + else + pkg_style = nil + end + + if pkg_style + tmp = @hash["#{pkg_style}"] + tmp_os = tmp["os"]? ? tmp["os"].to_s : "#{os}" + tmp_os_arch = tmp["os_arch"]? ? tmp["os_arch"].to_s : "#{os_arch}" + tmp_os_version = tmp["os_version"]? ? tmp["os_version"].to_s : "#{os_version}" + + tmp_os_mount = tmp["os_mount"]? ? tmp["os_mount"].to_s : "#{os_mount}" + mount_type = tmp_os_mount == "cifs" ? "nfs" : tmp_os_mount.dup + + common_dir = "#{mount_type}/#{tmp_os}/#{tmp_os_arch}/#{tmp_os_version}" + end + + return common_dir + end + def get_package_dir if @hash["cci-makepkg"]? || @hash["cci-depends"]? || @hash["build-pkg"]? - mount_type = os_mount == "cifs" ? "nfs" : os_mount.dup - common_dir = "#{mount_type}/#{os}/#{os_arch}/#{os_version}" + common_dir = get_pkg_common_dir end
if @hash["cci-makepkg"]?
- def get_pkg_common_dir
- common_dir = ""
- if @hash["cci-makepkg"]?
pkg_style = "cci-makepkg"
- elsif @hash["cci-depends"]?
pkg_style = "cci-depends"
- elsif @hash["build-pkg"]?
pkg_style = "build-pkg"
- else
pkg_style = nil
- end
- if pkg_style
tmp = @hash["#{pkg_style}"]
tmp_os = tmp["os"]? ? tmp["os"].to_s : "#{os}"
No need to use 'to_s' here, "#{}" will do this automatically. Just make 'tmp_os': JSON::Any | String.
tmp_os_arch = tmp["os_arch"]? ? tmp["os_arch"].to_s : "#{os_arch}"
tmp_os_version = tmp["os_version"]? ? tmp["os_version"].to_s : "#{os_version}"
tmp_os_mount = tmp["os_mount"]? ? tmp["os_mount"].to_s : "#{os_mount}"
mount_type = tmp_os_mount == "cifs" ? "nfs" : tmp_os_mount.dup
common_dir = "#{mount_type}/#{tmp_os}/#{tmp_os_arch}/#{tmp_os_version}"
- end
How about this, save the @hash[pkg_style]? first :
v1 = nil ["cci-makepkg", "cci-depends", "build-pkg"].each do |pkg_style| v1 = @hash[pkg_style]? break if v1 end
return "" unless v1 ...
Thanks, RenWen
- return common_dir
- end
- def get_package_dir if @hash["cci-makepkg"]? || @hash["cci-depends"]? || @hash["build-pkg"]?
mount_type = os_mount == "cifs" ? "nfs" : os_mount.dup
common_dir = "#{mount_type}/#{os}/#{os_arch}/#{os_version}"
common_dir = get_pkg_common_dir
end
if @hash["cci-makepkg"]?
-- 2.23.0
On Mon, Jan 11, 2021 at 10:22:58PM +0800, Ren Wen wrote:
- def get_pkg_common_dir
- common_dir = ""
- if @hash["cci-makepkg"]?
pkg_style = "cci-makepkg"
- elsif @hash["cci-depends"]?
pkg_style = "cci-depends"
- elsif @hash["build-pkg"]?
pkg_style = "build-pkg"
- else
pkg_style = nil
- end
- if pkg_style
tmp = @hash["#{pkg_style}"]
tmp_os = tmp["os"]? ? tmp["os"].to_s : "#{os}"
No need to use 'to_s' here, "#{}" will do this automatically. Just make 'tmp_os': JSON::Any | String.
I want it is string, so use to_s, keep the same after ":" value type.
tmp_os_arch = tmp["os_arch"]? ? tmp["os_arch"].to_s : "#{os_arch}"
tmp_os_version = tmp["os_version"]? ? tmp["os_version"].to_s : "#{os_version}"
tmp_os_mount = tmp["os_mount"]? ? tmp["os_mount"].to_s : "#{os_mount}"
mount_type = tmp_os_mount == "cifs" ? "nfs" : tmp_os_mount.dup
common_dir = "#{mount_type}/#{tmp_os}/#{tmp_os_arch}/#{tmp_os_version}"
- end
How about this, save the @hash[pkg_style]? first :
v1 = nil ["cci-makepkg", "cci-depends", "build-pkg"].each do |pkg_style| v1 = @hash[pkg_style]? break if v1 end
ok, this can reduce some code lines.
Thanks, Xueliang
return "" unless v1 ...
Thanks, RenWen
- return common_dir
- end
- def get_package_dir if @hash["cci-makepkg"]? || @hash["cci-depends"]? || @hash["build-pkg"]?
mount_type = os_mount == "cifs" ? "nfs" : os_mount.dup
common_dir = "#{mount_type}/#{os}/#{os_arch}/#{os_version}"
common_dir = get_pkg_common_dir
end
if @hash["cci-makepkg"]?
-- 2.23.0