github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/store/version.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package store
    10  
    11  import (
    12  	"io/ioutil"
    13  	"path/filepath"
    14  	"time"
    15  )
    16  
    17  const verCheckFilename = ".versioncheck"
    18  
    19  // VersionCheckTime returns the time of latest version check, if any.
    20  func VersionCheckTime() *time.Time {
    21  	content, err := ioutil.ReadFile(filepath.Join(dir, verCheckFilename))
    22  	if err != nil {
    23  		return nil
    24  	}
    25  	t, err := time.Parse(time.RFC3339, string(content))
    26  	if err != nil {
    27  		return nil
    28  	}
    29  	return &t
    30  }
    31  
    32  // SetVersionCheckTime set the latest version check to now.
    33  func SetVersionCheckTime() {
    34  	if err := ensureDir(dir); err != nil {
    35  		return
    36  	}
    37  	t := time.Now().Format(time.RFC3339)
    38  	ioutil.WriteFile(filepath.Join(dir, verCheckFilename), []byte(t), FilePerm)
    39  }