Example #1
0
func (env *Env) Write() {
	util.RemoveDir(env.dir)
	util.PrepareDir(env.dir)
	util.PrepareDir(getZenvPath())
	util.PrepareDir(getEnvsPath())
	env.writeInfo()
	env.items.Write(env.dir)
	if !env.global {
		env.addEnvDir()
	}
}
Example #2
0
func Clean(current string) {
	settings.Initialize(getZenvPath())
	tmpPath := storage.GetStoragePath(storage.TMP)
	for _, dir := range util.GetAllDir(tmpPath) {
		if current != dir {
			activated := util.ReadFile(path.Join(tmpPath, dir, ACTIVATED))
			for _, act := range activated {
				env := getLocalEnv(act)
				if env != nil {
					env.ReadSettings()
					env.items.Clean(settings.NewInfo(getZenvPath(), env.dir))
				}
			}
			util.RemoveDir(path.Join(tmpPath, dir))
		}
	}
}
Example #3
0
func ClearTemporal() {
	now := time.Now()
	for _, dir := range util.GetAllDir(GetStoragePath(TMP)) {
		last := util.ReadFile(getStorageFilePath(TMP, dir, LAST))
		if len(last) != 1 {
			updateLast(dir)
			continue
		}
		ti, err := time.Parse(time.ANSIC, last[0])
		if err == nil {
			if int(now.Sub(ti).Hours())/24 > remove {
				util.RemoveDir(GetStorageDir(TMP, dir))
			}
		} else {
			updateLast(dir)
		}
	}
}
Example #4
0
func (env *Env) Deactivate(pid string) {
	//Remove from list
	activated := GetActivated(pid)
	for i, actName := range activated {
		if actName == env.name {
			activated = append(activated[:i], activated[i+1:]...)
			break
		}
	}
	storage.WriteTemporal(pid, ACTIVATED, activated)

	if !isActivated(activated, env.name) {
		env.items.Deactivate(settings.NewInfo(getZenvPath(), env.dir))
		//TODO deactivate child envs
	}
	if len(activated) == 0 {
		util.RemoveDir(storage.GetStorageDir(storage.TMP, pid))
	}
}
Example #5
0
File: link.go Project: ryo33/zenv
func initializeLink(dir string) {
	pa := GetVBinPath(dir)
	util.RemoveDir(pa)
	util.PrepareDir(pa)
}