use cwd for agent update fixes #24
This commit is contained in:
parent
bee870bd58
commit
407f2a8072
@ -226,9 +226,15 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
|
||||
return
|
||||
}
|
||||
|
||||
f, err := createNixTmpFile()
|
||||
// more reliable method to get current working directory than os.Getwd()
|
||||
cwd := filepath.Dir(self)
|
||||
// create a tmpfile in same location as current binary
|
||||
// avoids issues with /tmp dir and other fs mount issues
|
||||
tmpfile := filepath.Join(cwd, GenerateAgentID())
|
||||
|
||||
f, err := os.Create(tmpfile)
|
||||
if err != nil {
|
||||
a.Logger.Errorln("AgentUpdate createNixTmpFile()", err)
|
||||
a.Logger.Errorln("AgentUpdate() os.Create(tmpfile)", err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
@ -260,30 +266,9 @@ func (a *Agent) AgentUpdate(url, inno, version string) {
|
||||
os.Chmod(f.Name(), 0755)
|
||||
err = os.Rename(f.Name(), self)
|
||||
if err != nil {
|
||||
a.Logger.Debugln("Detected /tmp on different filesystem")
|
||||
// rename does not work when src and dest are on different filesystems
|
||||
// so we need to manually copy it to the same fs then rename it
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
a.Logger.Errorln("AgentUpdate() os.Getwd():", err)
|
||||
a.Logger.Errorln("AgentUpdate() os.Rename():", err)
|
||||
return
|
||||
}
|
||||
// create a tmpfile in same fs as agent
|
||||
tmpfile := filepath.Join(cwd, GenerateAgentID())
|
||||
defer os.Remove(tmpfile)
|
||||
a.Logger.Debugln("Copying tmpfile from", f.Name(), "to", tmpfile)
|
||||
cperr := copyFile(f.Name(), tmpfile)
|
||||
if cperr != nil {
|
||||
a.Logger.Errorln("AgentUpdate() copyFile:", cperr)
|
||||
return
|
||||
}
|
||||
os.Chmod(tmpfile, 0755)
|
||||
rerr := os.Rename(tmpfile, self)
|
||||
if rerr != nil {
|
||||
a.Logger.Errorln("AgentUpdate() os.Rename():", rerr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if runtime.GOOS == "linux" && a.seEnforcing() {
|
||||
se := a.NewCMDOpts()
|
||||
|
Loading…
Reference in New Issue
Block a user