MCPcopy
hub / github.com/caddyserver/caddy / mkdirAllInherit

Function mkdirAllInherit

modules/logging/filewriter.go:314–341  ·  view source on GitHub ↗

mkdirAllInherit creates missing dirs using the nearest existing parent's permissions, normalized with r→x.

(dir string)

Source from the content-addressed store, hash-verified

312// mkdirAllInherit creates missing dirs using the nearest existing parent's
313// permissions, normalized with r→x.
314func mkdirAllInherit(dir string) error {
315 if fi, err := os.Stat(dir); err == nil && fi.IsDir() {
316 return nil
317 }
318 cur := dir
319 var parent string
320 for {
321 next := filepath.Dir(cur)
322 if next == cur {
323 parent = next
324 break
325 }
326 if fi, err := os.Stat(next); err == nil {
327 if !fi.IsDir() {
328 return fmt.Errorf("path component %s exists and is not a directory", next)
329 }
330 parent = next
331 break
332 }
333 cur = next
334 }
335 perm := os.FileMode(0o700)
336 if fi, err := os.Stat(parent); err == nil && fi.IsDir() {
337 perm = fi.Mode().Perm()
338 }
339 perm = normalizeDirPerm(perm)
340 return os.MkdirAll(dir, perm)
341}
342
343// mkdirAllFromFile creates missing dirs using the file's mode (with r→x) so
344// 0644 → 0755, 0600 → 0700, etc.

Callers 1

OpenWriterMethod · 0.85

Calls 2

normalizeDirPermFunction · 0.85
StatMethod · 0.80

Tested by

no test coverage detected