housekeeper

package
v0.0.0-...-ea708a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package housekeeper manages the local cache of CheeseGull, by always keeping track of the local state of the cache and keeping it to a low amount.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedBeatmap

type CachedBeatmap struct {
	ID          int
	NoVideo     bool
	LastUpdate  time.Time
	DataFolders []string
	// contains filtered or unexported fields
}

CachedBeatmap represents a beatmap that is held in the cache of CheeseGull.

func (*CachedBeatmap) CreateFile

func (c *CachedBeatmap) CreateFile() (*os.File, error)

CreateFile creates the File of the beatmap in the filesystem, and returns it in write mode.

func (*CachedBeatmap) DownloadCompleted

func (c *CachedBeatmap) DownloadCompleted(fileSize uint64, parentHouse *House)

DownloadCompleted must be called once the beatmap has finished downloading.

func (*CachedBeatmap) File

func (c *CachedBeatmap) File() (*os.File, error)

File opens the File of the beatmap from the filesystem.

func (*CachedBeatmap) FileSize

func (c *CachedBeatmap) FileSize() uint64

FileSize returns the FileSize of c.

func (*CachedBeatmap) GetLastAttempt

func (c *CachedBeatmap) GetLastAttempt() int

GetLastAttempt Get Last Attempt time for re-download in some cases ;d

func (*CachedBeatmap) IsDownloaded

func (c *CachedBeatmap) IsDownloaded() bool

IsDownloaded checks whether the beatmap has been downloaded.

func (*CachedBeatmap) MustBeDownloaded

func (c *CachedBeatmap) MustBeDownloaded()

MustBeDownloaded will check whether the beatmap is downloaded. If it is not, it will wait for it to become downloaded.

func (*CachedBeatmap) NotDownloaded

func (c *CachedBeatmap) NotDownloaded(parentHouse *House)

NotDownloaded must be called when file is fucking empty!

func (*CachedBeatmap) SetLastRequested

func (c *CachedBeatmap) SetLastRequested(t time.Time)

SetLastRequested changes the last requested time.

func (*CachedBeatmap) String

func (c *CachedBeatmap) String() string

func (*CachedBeatmap) UpdateFolders

func (c *CachedBeatmap) UpdateFolders(folders string) bool

type House

type House struct {
	MaxSize     uint64
	MaxSizeGB   int
	DataFolders []string
	State       []*CachedBeatmap
	StateMutex  sync.RWMutex
	// contains filtered or unexported fields
}

House manages the state of the cached beatmaps in the local filesystem.

func New

func New() *House

New creates a new house, initialised with the default values.

func (*House) AcquireBeatmap

func (h *House) AcquireBeatmap(c *CachedBeatmap) (*CachedBeatmap, bool)

AcquireBeatmap attempts to add a new CachedBeatmap to the state. In order to add a new CachedBeatmap to the state, one must not already exist in the state with the same ID, NoVideo and LastUpdate. In case one is already found, this is returned, alongside with false. If LastUpdate is newer than that of the beatmap stored in the state, then the beatmap in the state's downloaded status is switched back to false and the LastUpdate is changed. true is also returned, indicating that the caller now has the burden of downloading the beatmap.

In the case the cachedbeatmap has not been stored in the state, then it is added to the state and, like the case where LastUpdated has been changed, true is returned, indicating that the caller must now download the beatmap.

If you're confused attempting to read this, let me give you an example:

A: Yo, is this beatmap cached?
B: Yes, yes it is! Here you go with the information about it. No need to do
   anything else.
   ----
A: Yo, got this beatmap updated 2 hours ago. Have you got it cached?
B: Ah, I'm afraid that I only have the version updated 10 hours ago.
   Mind downloading the updated version for me?
   ----
A: Yo, is this beatmap cached?
B: Nope, I didn't know it existed before you told me. I've recorded its
   info now, but jokes on you, you now have to actually download it.
   Chop chop!

func (*House) CleanUp

func (h *House) CleanUp()

CleanUp ok

func (*House) LoadState

func (h *House) LoadState() error

LoadState attempts to load the state from cgbin.db

func (*House) RemoveNonZip

func (h *House) RemoveNonZip()

RemoveNonZip reads all the beatmaps currently in the house to ensure that they are all zip files. Those which are not get removed.

func (*House) StartCleaner

func (h *House) StartCleaner()

StartCleaner starts the process that will do the necessary housekeeping every time a cleanup is scheduled with scheduleCleanup.

func (*House) StateSizeAndRemovableMaps

func (h *House) StateSizeAndRemovableMaps() (totalSize uint64, removable []*CachedBeatmap)

i hate verbose names myself, but it was very hard to come up with something even as short as this.

func (*House) UpdateFolders

func (h *House) UpdateFolders(folders string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL