Skip to content

Commit

Permalink
[DT - 4] - Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Cedric Ngadeu committed Jun 20, 2019
1 parent d3984ba commit ac783c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 6 additions & 6 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type TGFApplication struct {
WithCurrentUser bool
WithDockerMount bool
DoUpdate bool
Swap string
SelfCopy string
}

// NewTGFApplication returns an initialized copy of TGFApplication along with the parsed CLI arguments
Expand Down Expand Up @@ -144,7 +144,7 @@ func NewTGFApplication(args []string) *TGFApplication {
app.Flag("config-files", "Set the files to look for (default: "+remoteDefaultConfigPath+")").PlaceHolder("<files>").StringVar(&app.ConfigFiles)
app.Flag("config-location", "Set the configuration location").PlaceHolder("<path>").StringVar(&app.ConfigLocation)
app.Flag("update", "Run the update ").Default(true).BoolVar(&app.DoUpdate)
app.Flag("swap", "Replace the executable at the provided path with the currently running one").PlaceHolder("<path>").StringVar(&app.Swap)
app.Flag("self-copy", "Replace the executable at the provided path with the currently running one").PlaceHolder("<path>").StringVar(&app.SelfCopy)

kingpin.CommandLine = app.Application
kingpin.HelpFlag = app.GetFlag("help-tgf")
Expand Down Expand Up @@ -216,15 +216,15 @@ func (app *TGFApplication) Run() int {
return 0
}

if app.Swap != "" {
SwapExecutables(app.Swap)
if app.SelfCopy != "" {
CopyExecutable(app.SelfCopy)
}

var dueForUpdate = lastRefresh(autoUpdateFileName) > 2*time.Hour
if app.Swap == "" && app.DoUpdate && dueForUpdate && RunUpdate() { // Passing app for logging only
if app.SelfCopy == "" && app.DoUpdate && dueForUpdate && RunUpdate() { // Passing app for logging only
app.Debug("got latest version")
touchImageRefresh(autoUpdateFileName)
ReRun(app.Swap)
ReRun(app.SelfCopy)
return 0
}

Expand Down
8 changes: 3 additions & 5 deletions update_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func RunUpdate() bool {
currentExecutableContent, err := ioutil.ReadFile(currentExecutablePath)
ioutil.WriteFile(homeExecutableDir, currentExecutableContent, 755)

Println("pathss", homeExecutableDir, currentExecutablePath)
os.Setenv("TGF_PATH", homeExecutableDir)

updateScript, err := fetchUpdateScript()
Expand Down Expand Up @@ -66,21 +65,20 @@ func ReRun(pathToSwap string) {
}
homeExecutablePath := path.Join(homeDir, ".tgf", "tgf")

cmd := exec.Command(homeExecutablePath, strings.Join(os.Args[1:], " "), "--swap", pathToSwap)
cmd := exec.Command(homeExecutablePath, strings.Join(os.Args[1:], " "), "--self-copy", pathToSwap)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Run()
}

// SwapExecutables Swaps the current executable with the one at the provided path
func SwapExecutables(pathToSwap string) bool {
// CopyExecutable Swaps the current executable with the one at the provided path
func CopyExecutable(pathToSwap string) bool {
currentExecutablePath, err := os.Executable()
if err != nil {
printWarning("Error getting executable path", err)
}

Println("swaping : ", pathToSwap, "with", currentExecutablePath)
currentExecutableContent, err := ioutil.ReadFile(currentExecutablePath)
ioutil.WriteFile(pathToSwap, currentExecutableContent, 755)

Expand Down

0 comments on commit ac783c9

Please sign in to comment.