OpenNHP/opennhp · error

path is not a regular file

Error message

path is not a regular file

What it means

After a successful os.Stat, Md5sum rejects paths that do not refer to a regular file (Mode().IsRegular() is false). Directories, device files, sockets, FIFOs and other special files are refused because hashing them is either meaningless (directories) or can block indefinitely (FIFOs/devices).

Solutions

  1. Confirm the target is a regular file: run stat -c '%F' <path> and expect 'regular file'
  2. Correct the configured path to point to the actual file rather than a directory or special file
  3. If you need to hash a directory's contents, hash the files inside it individually or hash an archive of it

Example fix

// before
sum, err := utils.Md5sum("/opt/nhp/plugins") // directory
// after
sum, err := utils.Md5sum("/opt/nhp/plugins/ta_plugin.so")
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(p); err != nil || !info.Mode().IsRegular() { return err }

Prevention

When it happens

Trigger: Calling utils.Md5sum on a directory path, on /dev/null or another device node, on a named pipe, or on a unix socket instead of a regular file path.

Common situations: Config points the TA file setting at a directory (e.g. a plugins folder) instead of the .so file; a placeholder path like /dev/null was left in config; a symlink to a directory was passed.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/eaa3005c00231694. Report an issue: GitHub.

Appendix: source

Thrown at nhp/utils/crypto.go:131

		return "", ""
	}
	pivKey := x509.MarshalPKCS1PrivateKey(privateKey)
	pubKey := x509.MarshalPKCS1PublicKey(&privateKey.PublicKey)

	return base64.StdEncoding.EncodeToString(pivKey), base64.StdEncoding.EncodeToString(pubKey)
}

// Md5sum computes MD5 checksum for file integrity verification (not cryptographic security)
//
//nolint:gosec // G401: MD5 used for file integrity checksums, not for cryptographic security
func Md5sum(fullFilePath string) (string, error) {
	fileInfo, err := os.Stat(fullFilePath)
	if err != nil {
		return "", fmt.Errorf("file not found: %w", err)
	}

	if !fileInfo.Mode().IsRegular() {
		return "", fmt.Errorf("path is not a regular file")
	}

	file, err := os.Open(fullFilePath) //nolint:gosec // G304: Path validated by os.Stat above
	if err != nil {
		return "", fmt.Errorf("failed to open file: %w", err)
	}
	defer file.Close()

	hasher := md5.New()

	if _, err := io.Copy(hasher, file); err != nil {
		return "", fmt.Errorf("failed to read file content: %w", err)
	}

	// Convert hash to hex string
	return hex.EncodeToString(hasher.Sum(nil)), nil
}

View on GitHub (pinned to 6e04ca5ff0)