caddyserver/caddy · error

path component exists and is not a directory

Error message

path component %s exists and is not a directory

What it means

mkdirAllInherit guard while walking up to the nearest existing ancestor for permission inheritance: a path component on the way exists but is a file, not a directory, so the target directory cannot be created beneath it; the offending component is named.

Solutions

  1. Choose a different log file path, or remove/rename the conflicting non-directory file at that path.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/logging/filewriter.go:328 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/6e17cc64c4ba7326. Report an issue: GitHub.

Appendix: source

Thrown at modules/logging/filewriter.go:328

}

// mkdirAllInherit creates missing dirs using the nearest existing parent's
// permissions, normalized with r→x.
func mkdirAllInherit(dir string) error {
	if fi, err := os.Stat(dir); err == nil && fi.IsDir() {
		return nil
	}
	cur := dir
	var parent string
	for {
		next := filepath.Dir(cur)
		if next == cur {
			parent = next
			break
		}
		if fi, err := os.Stat(next); err == nil {
			if !fi.IsDir() {
				return fmt.Errorf("path component %s exists and is not a directory", next)
			}
			parent = next
			break
		}
		cur = next
	}
	perm := os.FileMode(0o700)
	if fi, err := os.Stat(parent); err == nil && fi.IsDir() {
		perm = fi.Mode().Perm()
	}
	perm = normalizeDirPerm(perm)
	return os.MkdirAll(dir, perm)
}

// mkdirAllFromFile creates missing dirs using the file's mode (with r→x) so
// 0644 → 0755, 0600 → 0700, etc.
func mkdirAllFromFile(dir string, fileMode os.FileMode) error {
	if fi, err := os.Stat(dir); err == nil && fi.IsDir() {

View on GitHub (pinned to 50e54ee279)