package server

import (
	"github.com/pterodactyl/wings/parser"
	"sync"
)

// Parent function that will update all of the defined configuration files for a server
// automatically to ensure that they always use the specified values.
func (s *Server) UpdateConfigurationFiles() {
	wg := new(sync.WaitGroup)

	files := s.ProcessConfiguration().ConfigurationFiles
	for _, v := range files {
		wg.Add(1)

		go func(f parser.ConfigurationFile, server *Server) {
			defer wg.Done()

			p, err := server.Filesystem.SafePath(f.FileName)
			if err != nil {
				server.Log().WithField("error", err).Error("failed to generate safe path for configuration file")

				return
			}

			if err := f.Parse(p, false); err != nil {
				server.Log().WithField("error", err).Error("failed to parse and update server configuration file")
			}
		}(v, s)
	}

	wg.Wait()
}
package server

import (
	"github.com/gammazero/workerpool"
	"runtime"
)

// Parent function that will update all of the defined configuration files for a server
// automatically to ensure that they always use the specified values.
func (s *Server) UpdateConfigurationFiles() {
	pool := workerpool.New(runtime.GOMAXPROCS(0))

	files := s.ProcessConfiguration().ConfigurationFiles
	for _, cf := range files {
		f := cf

		pool.Submit(func() {
			p, err := s.Filesystem.SafePath(f.FileName)
			if err != nil {
				s.Log().WithField("error", err).Error("failed to generate safe path for configuration file")

				return
			}

			if err := f.Parse(p, false); err != nil {
				s.Log().WithField("error", err).Error("failed to parse and update server configuration file")
			}
		})
	}

	pool.StopWait()
}
Use a workerpool for configuration file updates
Use a workerpool for configuration file updates

Co-Authored-By: Jakob <0708d49e9b6eea40f2835438410a265908e17890@users.noreply.github.com>
