Chromium Code Reviews| Index: cipd/client/cipd/client.go |
| diff --git a/cipd/client/cipd/client.go b/cipd/client/cipd/client.go |
| index 008ddaf1568a9e90ebc74836424264a7340dad84..f1658a2fc4df52739b3d6919a2d484f488d71a95 100644 |
| --- a/cipd/client/cipd/client.go |
| +++ b/cipd/client/cipd/client.go |
| @@ -32,6 +32,7 @@ package cipd |
| import ( |
| "bufio" |
| + "encoding/json" |
| "fmt" |
| "io" |
| "net/http" |
| @@ -52,6 +53,7 @@ import ( |
| "github.com/luci/luci-go/cipd/client/cipd/common" |
| "github.com/luci/luci-go/cipd/client/cipd/internal" |
| "github.com/luci/luci-go/cipd/client/cipd/local" |
| + "github.com/luci/luci-go/cipd/version" |
| ) |
| // PackageACLChangeAction defines a flavor of PackageACLChange. |
| @@ -719,6 +721,32 @@ func init() { |
| clientPackage = fmt.Sprintf("%s/%s-%s", clientPackageBase, platform, arch) |
| } |
| +func (client *clientImpl) ensureClientVersionInfo(ctx context.Context, fs local.FileSystem, pin common.Pin, exePath string) { |
| + verFile := version.GetVersionFile(exePath) |
| + vfStat, err := os.Stat(verFile) |
|
Vadim Sh.
2016/11/27 01:25:55
I'd remove both of these checks and just read the
iannucci
2016/11/29 01:46:20
Done.
|
| + if err == nil { |
| + eStat, err := os.Stat(exePath) |
| + if err == nil { |
| + if vfStat.ModTime().After(eStat.ModTime()) { |
| + // version file already up to date |
| + return |
| + } |
| + } |
| + } |
| + // there was an error statting one or both files, or the version file is older |
| + // than the exe. Proceed with EnsureFile. |
| + |
| + err = fs.EnsureFile(ctx, verFile, func(of *os.File) error { |
|
Vadim Sh.
2016/11/27 01:25:55
I forgot, does it create a full path? i.e. if ".ve
iannucci
2016/11/29 01:46:20
Yes :)
|
| + return json.NewEncoder(of).Encode(version.Info{ |
| + PackageName: pin.PackageName, |
| + InstanceID: pin.InstanceID, |
| + }) |
| + }) |
| + if err != nil { |
| + logging.Warningf(ctx, "Unable to update version info %q: %s", verFile, err) |
| + } |
| +} |
| + |
| func (client *clientImpl) MaybeUpdateClient(ctx context.Context, fs local.FileSystem, targetVersion, currentHash, destination string) error { |
| if err := common.ValidateFileHash(currentHash); err != nil { |
| return err |
| @@ -741,7 +769,8 @@ func (client *clientImpl) MaybeUpdateClient(ctx context.Context, fs local.FileSy |
| } |
| } |
| if exeHash == currentHash { |
| - // already up-to-date |
| + // already up-to-date. Make sure version file is up to date. |
| + client.ensureClientVersionInfo(ctx, fs, pin, destination) |
| return nil |
| } |
| @@ -758,11 +787,18 @@ func (client *clientImpl) MaybeUpdateClient(ctx context.Context, fs local.FileSy |
| } |
| client.doBatchAwareOp(ctx, batchAwareOpSaveTagCache) |
| if info.clientBinary.SHA1 == currentHash { |
| - // already up-to-date, but the cache didn't know that. |
| + // already up-to-date, but the cache didn't know that. Make sure version |
| + // file is update. |
| + client.ensureClientVersionInfo(ctx, fs, pin, destination) |
| return nil |
| } |
| - return client.installClient(ctx, fs, info.clientBinary.FetchURL, destination) |
| + if err := client.installClient(ctx, fs, info.clientBinary.FetchURL, destination); err != nil { |
| + return err |
| + } |
| + |
| + client.ensureClientVersionInfo(ctx, fs, pin, destination) |
| + return nil |
| } |
| func (client *clientImpl) RegisterInstance(ctx context.Context, instance local.PackageInstance, timeout time.Duration) error { |