Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DT-4] Auto-update feature #74

Closed
wants to merge 24 commits into from
Closed

Conversation

ycngadeu-coveo
Copy link
Contributor

Done:

  • Added an auto update feature
  • Added a no-update flag to skip the auto update

TODO:

  • Some tests
  • Refactoring
  • Better logging

@coveralls
Copy link

coveralls commented Jun 12, 2019

Pull Request Test Coverage Report for Build 951

  • 3 of 97 (3.09%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-4.0004%) to 39.757%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cli.go 3 18 16.67%
update_unix.go 0 79 0.0%
Files with Coverage Reduction New Missed Lines %
cli.go 1 73.87%
Totals Coverage Status
Change from base Build 923: -4.0004%
Covered Lines: 392
Relevant Lines: 986

💛 - Coveralls

Copy link
Contributor

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! I have a few comments for you

cli.go Outdated Show resolved Hide resolved
tgf_auto_update.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
tgf_auto_update.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
auto_update.go Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
julienduchesne
julienduchesne previously approved these changes Jun 17, 2019
Copy link
Contributor

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!
How about you @jocgir ?

@julienduchesne
Copy link
Contributor

julienduchesne commented Jun 18, 2019

Wait up. Let's review Linux and Windows independently, please. The other PR also should've been merged independently.

Essentially, you shouldn't bunch up 3 PRs worth of stuff in a single one. I will merge the update script PR into master but you need to split up linux and Windows stuff

@julienduchesne
Copy link
Contributor

Here I merged the linux script update. To be clear, open:
a PR for the Windows update script
a PR for the linux auto update
a PR where you add Windows auto update to the linux codebase

I think there will be enough discussion to warrant three PRs

update_unix.go Outdated Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
Copy link
Contributor

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sad trombone
I'm getting
environment: line 33: /home/jduchesne/repos/tgf/tgf: Text file busy

We may have to do the Windows trick even on linux

update_unix.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
cli.go Outdated Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
update_unix.go Outdated Show resolved Hide resolved
@@ -208,5 +217,21 @@ func (app *TGFApplication) Run() int {
Printf("tgf v%s\n", version)
return 0
}

if app.DeleteCopy {
os.Remove(getHomeFileName("tgf"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give it a hidden name. not tgf

}

if app.CopyPath != "" {
cloneExecutableAt(app.CopyPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should delete the copy if it exists

func getCurrentExecutablePath() string {
executablePath, err := os.Executable()
if err != nil {
printWarning("Error getting executable path", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an error. This will return "" and then the next command will fail

"path/filepath"
)

// RunUpdate runs the update on the current tgf executable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deserves to be way better documented. An outsider has to be able to figure out what will happen with this doc

cmd.Run()
}

func cloneExecutableAt(newExecutablePath string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in another file. It shouldn't be private and it should be documented

var dueForUpdate = lastRefresh(autoUpdateFileName) > 2*time.Hour
if app.DoUpdate && dueForUpdate && RunUpdate() {
touchImageRefresh(autoUpdateFileName)
ReRunCopy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call that ForwardCallToNewVersion. It's long but descriptive

@@ -10,8 +10,12 @@ import (
)

func getTouchFilename(image string) string {
return getHomeFileName(util.EncodeBase64Sha1(image))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a whole bunch of duplicated logic and no clear distinction where the code should go (this file or update_*.go). I suggest putting all homedir handling to a file called homedir.go. You could then have simple commands that only need the filename as parameter:
Read
Write (This can replace touch)

@ycngadeu-coveo ycngadeu-coveo deleted the feature/dt-4-auto-update branch June 26, 2019 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants