Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Create temporary directory to store files in. Convert Load call use p…
Browse files Browse the repository at this point in the history
…ass in array of files instead of just one file path
  • Loading branch information
geauxvirtual committed Oct 26, 2015
1 parent 1205ef6 commit 40fd2c1
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions mgmt/rest/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ func (s *Server) loadPlugin(w http.ResponseWriter, r *http.Request, _ httprouter
return
}
}
files[i], err = writeFile(s.mm.GetAutodiscoverPaths(), p.FileName(), b, files[0])
files[i], err = writeFile(s.mm.GetAutodiscoverPaths(), p.FileName(), b)
if err != nil {
respond(500, rbody.FromError(err), w)
return
}
i++
}
restLogger.Info("Loading plugin: ", files[0])
pl, err := s.mm.Load(files[0])
pl, err := s.mm.Load(files...)
if err != nil {
var ec int
restLogger.Error(err)
Expand All @@ -142,21 +142,17 @@ func (s *Server) loadPlugin(w http.ResponseWriter, r *http.Request, _ httprouter
}
}

func writeFile(autoPaths []string, filename string, b []byte, fqfile string) (string, error) {
var f *os.File
var err error
func writeFile(autoPaths []string, filename string, b []byte) (string, error) {
// Create temporary directory
dir, err := ioutil.TempDir("", "")
if err != nil {
return "", err
}
if len(autoPaths) > 0 {
// write to first autoPath
f, err = os.Create(path.Join(autoPaths[0], filename))
} else {
// write to temp location for binary
if fqfile == "" {
f, err = ioutil.TempFile("", filename)
} else {
// write asc to same location as binary
f, err = os.Create(fqfile + ".asc")
}
dir = autoPaths[0]
}
f, err := os.Create(path.Join(dir, filename))
if err != nil {
return "", err
}
Expand Down

0 comments on commit 40fd2c1

Please sign in to comment.