Exemplo n.º 1
0
Arquivo: gc.go Projeto: 9seconds/ah
// GC implements g (garbage collecting) command.
func GC(gcType GcType, gcDir GcDir, param int, env *environments.Environment) {
	listFunction := env.GetTracesFileInfos
	fileNameFunction := env.GetTraceFileName
	if gcDir == GcBookmarksDir {
		listFunction = env.GetBookmarksFileInfos
		fileNameFunction = env.GetBookmarkFileName
	}

	fileInfos, err := listFunction()
	if err != nil {
		utils.Logger.Panic("Cannot fetch the list of trace filenames")
	}
	infoSorter := fileInfoSorter{content: fileInfos}
	sort.Sort(infoSorter)

	switch gcType {
	case GcKeepLatest:
		fileInfos = infoSorter.Tail(param)
	case GcOlderThan:
		timestamp := time.Now().Unix() - secondsInDay*int64(param)
		fileInfos = infoSorter.YoungerThan(timestamp)
	default:
		fileInfos = infoSorter.content
	}

	for _, info := range fileInfos {
		utils.RemoveWithLogging(fileNameFunction(info.Name()))
	}
}
Exemplo n.º 2
0
// RemoveBookmarks removes the list of bookmarks from the storage.
func RemoveBookmarks(bookmarks []string, env *environments.Environment) {
	for _, bookmark := range bookmarks {
		utils.RemoveWithLogging(env.GetBookmarkFileName(bookmark))
	}
}