Files
ThothII/tools/tht/internal/safeio/publish.go
T

16 lines
538 B
Go

package safeio
import (
"os"
"path/filepath"
)
// PublishCanonicalNewFile durably publishes complete bytes without replacing an existing
// target. A crash before publication can leave a private temporary file, never a partial target.
func PublishCanonicalNewFile(path string, contents []byte, mode os.FileMode) error {
if ValidateCanonicalPath(path) != nil || ValidatePrivateDirectory(filepath.Dir(path)) != nil || (mode != 0o600 && mode != 0o644) {
return ErrUnsafeFile
}
return publishCanonicalNewFile(path, contents, mode)
}