Exemple #1
0
func Read() {
	cacheFile = filepath.Join(os.Getenv("GOPATH"), cacheFileName)

	cache = make(map[string]time.Time)

	if !util.Exists(cacheFile) {
		return
	}

	if clear {
		err := os.Remove(cacheFile)
		if err != nil {
			util.Fatal(err)
		}
		return
	}

	util.Verbose("Reading cache file from " + cacheFile)

	data, err := ioutil.ReadFile(cacheFile)
	if err != nil {
		util.Fatal(err)
	}

	err = json.Unmarshal(data, &cache)
	if err != nil {
		return
	}
}
Exemple #2
0
// Write writes the cache out to disk
func Write() {
	if skip {
		return
	}

	var buf bytes.Buffer
	str, err := json.Marshal(cache)
	if err == nil {
		json.Indent(&buf, str, "", "    ")
		data := []byte(buf.String() + "\n")

		util.Verbose("Writing cache file to " + cacheFile)

		err = ioutil.WriteFile(cacheFile, data, 0644)
		if err != nil {
			util.Fatal(err)
		}
	}
	return
}
Exemple #3
0
// Print displays a message if a newer version of depman is available
// this should only be called after Check()
func Print() {
	if !checkCalled {
		util.Fatal(colors.Red("You must call upgrade.Check() before upgrade.Print()"))
	}

	// if the command used was self-upgrade, we can just return
	if selfCalled {
		return
	}

	ref := <-channel

	if checkError != nil {
		util.Verbose(colors.Yellow("Upgrade Check Error: " + checkError.Error()))
	}

	if ref != none {
		fmt.Println(colors.Yellow(fmt.Sprintf(message, ref)))
	}
}
Exemple #4
0
// Read reads the cache from disk
func Read() {
	parts := strings.Split(os.Getenv("GOPATH"), ":")
	cacheFile = filepath.Join(parts[0], cacheFileName)

	cache = make(map[string]time.Time)

	if !util.Exists(cacheFile) {
		return
	}

	util.Verbose("Reading cache file from " + cacheFile)

	data, err := ioutil.ReadFile(cacheFile)
	if err != nil {
		util.Fatal(err)
	}

	err = json.Unmarshal(data, &cache)
	if err != nil {
		return
	}
}