Skip to content

Commit

Permalink
find tarballs' difference
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Feb 19, 2020
1 parent d670a65 commit 5b5f258
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions service_parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"bufio"
"os"
"path/filepath"
"regexp"
)

func parseService(wd string) map[string]struct{} {
re := regexp.MustCompile(`path">(.*?)<`)
tgz := make(map[string]struct{})
service := filepath.Join(wd, "_service")
if _, err := os.Stat(service); !os.IsNotExist(err) {
f, _ := os.Open(service)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
t := scanner.Text()
if re.MatchString(t) {
t = re.FindStringSubmatch(t)[1]
tgz[filepath.Base(t)] = struct{}{}
}
}
f.Close()
}
return tgz
}
17 changes: 17 additions & 0 deletions tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ func (tb Tarballs) Append(uri string) {
}
}

func (tb Tarballs) diff(m map[string]struct{}, wd string) {
s := "#!/bin/bash\n"
for k := range tb {
tgz := filepath.Base(k)
if _, ok := m[tgz]; !ok {
log.Printf("%s should be removed\n", tgz)
s += "osc delete " +tgz+"\n"
}
}
ioutil.WriteFile(filepath.Join(wd, "remove.sh"), []byte(s), 0755)
}

// ToService convert tarball map to _service
func (tb Tarballs) ToService(wd string) {
s := "<services>\n"
Expand All @@ -33,6 +45,11 @@ func (tb Tarballs) ToService(wd string) {
s += "\t</service>\n"
}
s += "</services>\n"

m := parseService(wd)
if m != nil {
tb.diff(m, wd)
}
ioutil.WriteFile(filepath.Join(wd, "_service"), []byte(s), 0644)
}

Expand Down

0 comments on commit 5b5f258

Please sign in to comment.