2019-04-04 05:49:15 +00:00
|
|
|
package server
|
|
|
|
|
2019-04-06 23:53:22 +00:00
|
|
|
import (
|
2019-11-17 01:01:38 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-09-27 19:24:08 +00:00
|
|
|
"github.com/pterodactyl/wings/server/filesystem"
|
2019-04-06 23:53:22 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2020-09-27 19:24:08 +00:00
|
|
|
func (s *Server) Filesystem() *filesystem.Filesystem {
|
|
|
|
return s.fs
|
2019-04-07 21:45:23 +00:00
|
|
|
}
|
2019-11-16 23:48:50 +00:00
|
|
|
|
|
|
|
// Ensures that the data directory for the server instance exists.
|
2020-09-27 19:24:08 +00:00
|
|
|
func (s *Server) EnsureDataDirectoryExists() error {
|
|
|
|
if _, err := os.Stat(s.fs.Path()); err != nil && !os.IsNotExist(err) {
|
2019-11-17 01:05:21 +00:00
|
|
|
return errors.WithStack(err)
|
2019-11-16 23:48:50 +00:00
|
|
|
} else if err != nil {
|
|
|
|
// Create the server data directory because it does not currently exist
|
|
|
|
// on the system.
|
2020-09-27 19:24:08 +00:00
|
|
|
if err := os.MkdirAll(s.fs.Path(), 0700); err != nil {
|
2019-11-17 01:05:21 +00:00
|
|
|
return errors.WithStack(err)
|
2019-11-16 23:48:50 +00:00
|
|
|
}
|
2020-09-13 04:48:04 +00:00
|
|
|
|
2020-09-27 19:24:08 +00:00
|
|
|
if err := s.fs.Chown("/"); err != nil {
|
|
|
|
s.Log().WithField("error", err).Warn("failed to chown server data directory")
|
2020-09-13 04:48:04 +00:00
|
|
|
}
|
2019-11-16 23:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-02-02 21:41:15 +00:00
|
|
|
}
|