MCPcopy Index your code
hub / github.com/foxcpp/maddy / InitDirs

Function InitDirs

maddy.go:270–311  ·  view source on GitHub ↗
(c *container.C)

Source from the content-addressed store, hash-verified

268}
269
270func InitDirs(c *container.C) error {
271 if c.Config.StateDirectory == "" {
272 c.Config.StateDirectory = DefaultStateDirectory
273 }
274 if c.Config.RuntimeDirectory == "" {
275 c.Config.RuntimeDirectory = DefaultRuntimeDirectory
276 }
277 if c.Config.LibexecDirectory == "" {
278 c.Config.LibexecDirectory = DefaultLibexecDirectory
279 }
280
281 if err := ensureDirectoryWritable(c.Config.StateDirectory); err != nil {
282 return err
283 }
284 if err := ensureDirectoryWritable(c.Config.RuntimeDirectory); err != nil {
285 return err
286 }
287
288 // Make sure all paths we are going to use are absolute
289 // before we change the working directory.
290 if !filepath.IsAbs(c.Config.StateDirectory) {
291 return errors.New("statedir should be absolute")
292 }
293 if !filepath.IsAbs(c.Config.RuntimeDirectory) {
294 return errors.New("runtimedir should be absolute")
295 }
296 if !filepath.IsAbs(c.Config.LibexecDirectory) {
297 return errors.New("-libexec should be absolute")
298 }
299
300 // Change the working directory to make all relative paths
301 // in configuration relative to state directory.
302 if err := os.Chdir(c.Config.StateDirectory); err != nil {
303 log.Println(err)
304 }
305
306 config.StateDirectory = c.Config.StateDirectory
307 config.RuntimeDirectory = c.Config.RuntimeDirectory
308 config.LibexecDirectory = c.Config.LibexecDirectory
309
310 return nil
311}
312
313func ensureDirectoryWritable(path string) error {
314 if err := os.MkdirAll(path, 0o700); err != nil {

Callers 2

getCfgBlockModuleFunction · 0.92
moduleConfigureFunction · 0.85

Calls 2

PrintlnFunction · 0.92
ensureDirectoryWritableFunction · 0.85

Tested by

no test coverage detected