func gen(dir string, names []string) { logger := Logger.WithField("state", "gen_file") logger.WithFields(logrus.Fields{ "type": "info", "info": "gen file start", }).Info("gen file start") _, err := os.Stat(filepath.Join(dir, "problem.toml")) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("\"problem.toml\" does not exist") } p, err := libra.Load(dir, logger) var a []libra.SrcInfo //answer add for _, x := range p.Answer { a = append(a, libra.SrcInfo{Name: x.Name, Type: libra.ANS}) } //checker add a = append(a, libra.SrcInfo{Name: p.Checker, Type: libra.CHK}) //generator add for _, x := range p.Generator { a = append(a, libra.SrcInfo{Name: x.Name, Type: libra.GEN}) } //solution add a = append(a, libra.SrcInfo{Name: p.Solution, Type: libra.SOL}) //validator add a = append(a, libra.SrcInfo{Name: p.Validator, Type: libra.VAL}) //trygen start for _, x := range a { if contain(x.Name, names) { tryGen(dir, x.Name, logger) } } if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("Loading failed.") } logger.WithFields(logrus.Fields{ "type": "info", "info": "gen file end"}).Infof("add file end") }
func rem(dir, name string) { logger := Logger.WithField("state", "rem_file") logger.WithFields(logrus.Fields{ "type": "info", "info": "remove file start", }).Info("rem file start") if name == "" { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": "empty string", }).Fatal("empty string is not allowed") } _, err := os.Stat(filepath.Join(dir, "problem.toml")) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("\"problem.toml\" does not exist") } p, err := libra.Load(dir, logger) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("Loading failed.") } ok := false //answer for i := 0; i < len(p.Answer); { if p.Answer[i].Name == name { p.Answer = append(p.Answer[:i], p.Answer[i+1:]...) ok = true } else { i++ } } //checker if p.Checker == name { p.Checker = "" ok = true } //generator for i := 0; i < len(p.Generator); { if p.Generator[i].Name == name { p.Generator = append(p.Generator[:i], p.Generator[i+1:]...) ok = true } else { i++ } } //solution if p.Solution == name { p.Solution = "" ok = true } //validator if p.Validator == name { p.Validator = "" ok = true } if !ok { logger.WithFields(logrus.Fields{ "type": "info", "error": libra.IE, }).Warnf("file not found: %s", name) } err = libra.Save(dir, p, logger) if err != nil { logger.WithFields(logrus.Fields{ "type": "error", "error": libra.IE, "info": err.Error(), }).Fatal("Save failed.") } logger.WithFields(logrus.Fields{ "type": "info", "info": "rem file end"}).Infof("remove file end") }