downloader/local_file_check.go
2023-01-30 21:28:25 +01:00

32 lines
633 B
Go

package main
import (
"errors"
"os"
"path/filepath"
"git.milar.in/nyaanime/logic"
"git.milar.in/nyaanime/model"
)
func IsCurrentlyDownloading(animeEp model.AnimeEpisode) bool {
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
_, err := os.Stat(animeEpPath)
return !errors.Is(err, os.ErrNotExist)
}
func SetCurrentlyDownloading(animeEp model.AnimeEpisode) error {
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "lock")
dir := filepath.Dir(animeEpPath)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
file, err := os.Create(animeEpPath)
if err != nil {
defer file.Close()
}
return err
}