From 3dc121bc71678ed2a63c9725b8ee67496204d266 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 3 Jul 2023 14:31:55 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EC=A0=84=EC=97=90=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=EA=B0=80=20=EC=9D=BC=EC=B0=8D=20=EB=B6=99=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/http_api.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/server/http_api.go b/server/http_api.go index 6908172..142f4fb 100644 --- a/server/http_api.go +++ b/server/http_api.go @@ -34,6 +34,16 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) { enc.Encode(allHosts) } +func readTagsFromFile(paths ...string) string { + raw, _ := os.ReadFile(path.Join(paths...)) + if len(raw) > 0 { + tag := string(raw) + return strings.Trim(tag, "\n") + } + + return "" +} + func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) { files, err := os.ReadDir(h.deployPath) if err != nil { @@ -44,18 +54,15 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request getVersions := func(name string) []string { vers, _ := os.ReadDir(path.Join(h.deployPath, name)) - mytags, _ := os.ReadFile(path.Join(h.deployPath, name, "@tags")) - + mytags := readTagsFromFile(h.deployPath, name, "@tags") out := []string{ - string(mytags), + mytags, } for _, fd := range vers { if fd.IsDir() { ver := fd.Name() files, _ := os.ReadDir(path.Join(h.deployPath, name, ver)) - vertags, _ := os.ReadFile(path.Join(h.deployPath, name, ver, "@tags")) - ver = ver + string(mytags) + string(vertags) - + vertags := readTagsFromFile(h.deployPath, name, ver, "@tags") if len(files) > 0 { for _, file := range files { if strings.HasPrefix(file.Name(), "@") { @@ -63,7 +70,7 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request } downloadpath := path.Join(sub_folder_name_deploys, name, ver, file.Name()) - ver = fmt.Sprintf("%s:%s", ver, downloadpath) + ver = fmt.Sprintf("%s:%s", ver+mytags+vertags, downloadpath) break } } @@ -115,10 +122,10 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque if version == "config" { filename = path.Join(h.deployPath, name, version, "config"+ext) - tags, _ := os.ReadFile(path.Join(h.deployPath, name, version, "@tags")) - if !strings.Contains(string(tags), "#hidden") { - tags = []byte(string(tags) + "#hidden") - os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), tags, 0644) + tags := readTagsFromFile(h.deployPath, name, version, "@tags") + if !strings.Contains(tags, "#hidden") { + tags = tags + "#hidden" + os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), []byte(tags), 0644) } } else { filename = path.Join(h.deployPath, name, version, name+ext)