コード例 #1
0
ファイル: gc.go プロジェクト: 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()))
	}
}
コード例 #2
0
ファイル: remove_bookmarks.go プロジェクト: 9seconds/ah
// 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))
	}
}