frontend: move started file at a dedicated path

This commit is contained in:
nemunaire 2018-01-22 18:09:05 +01:00
parent 3f1f60030c
commit 2e3b262a78
2 changed files with 7 additions and 6 deletions

View File

@ -17,12 +17,14 @@ func main() {
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
var prefix = flag.String("prefix", "/", "Request path prefix to strip (from proxy)")
var teamsDir = flag.String("teams", "./TEAMS/", "Base directory where find existing teams")
flag.StringVar(&settings.SettingsDir, "settings", settings.SettingsDir, "Base directory where load and save settings")
flag.StringVar(&settings.SettingsDir, "settings", settings.SettingsDir, "Base directory where read settings")
flag.StringVar(&startedFile, "startedFile", startedFile, "Path to the file to create/remove whether or not the challenge is running")
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
flag.Parse()
log.SetPrefix("[frontend] ")
startedFile = path.Clean(startedFile)
SubmissionDir = path.Clean(SubmissionDir)
TmpSubmissionDir = path.Join(SubmissionDir, ".tmp")

View File

@ -3,19 +3,18 @@ package main
import (
"log"
"os"
"path"
"time"
fronttime "srs.epita.fr/fic-server/frontend/time"
"srs.epita.fr/fic-server/settings"
)
const startedFile = "started"
var startedFile = "started"
var touchTimer *time.Timer = nil
func touchStartedFile() {
if fd, err := os.Create(path.Join(settings.SettingsDir, startedFile)); err == nil {
if fd, err := os.Create(startedFile); err == nil {
log.Println("Started! Go, Go, Go!!")
fd.Close()
} else {
@ -32,8 +31,8 @@ func reloadSettings(config settings.FICSettings) {
if startSub > 0 {
log.Println("Challenge will starts at", config.Start, "in", startSub)
if _, err := os.Stat(path.Join(settings.SettingsDir, startedFile)); !os.IsNotExist(err) {
os.Remove(path.Join(settings.SettingsDir, startedFile))
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
os.Remove(startedFile)
}
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile)