Skip to content

Commit

Permalink
Merge pull request jpillora#57 from tgulacsi/windows56
Browse files Browse the repository at this point in the history
Implement weird overwrite logic for windows
  • Loading branch information
jpillora authored Jul 10, 2020
2 parents 7279a36 + fcf3e6b commit 36ed46f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion proc_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (mp *master) fetch() {
return
}
//overwrite!
if err := move(mp.binPath, tmpBinPath); err != nil {
if err := overwrite(mp.binPath, tmpBinPath); err != nil {
mp.warnf("failed to overwrite binary: %s", err)
return
}
Expand Down
4 changes: 4 additions & 0 deletions proc_slave_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ func (sp *slave) watchParent() error {
}()
return nil
}

func overwrite(dst, src string) error {
return move(dst, src)
}
17 changes: 16 additions & 1 deletion proc_slave_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package overseer
import (
"context"
"fmt"
"github.com/StackExchange/wmi"
"os"
"strings"
"time"

"github.com/StackExchange/wmi"
)

var (
Expand Down Expand Up @@ -112,3 +114,16 @@ func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, con
return err
}
}

// overwrite: see https://github.com/jpillora/overseer/issues/56#issuecomment-656405955
func overwrite(dst, src string) error {
old := strings.TrimSuffix(dst, ".exe") + "-old.exe"
if err := move(old, dst); err != nil {
return err
}
if err := move(dst, src); err != nil {
return err
}
os.Remove(old)
return nil
}

0 comments on commit 36ed46f

Please sign in to comment.