Make the template-file utilities safe to use as the generator's filesystem boundary.
harbor run -t mimo-v2.6-rl/format-code-task-000701harbor download mimo-v2.6-rl/format-code-task-000701Fix the following issue:
Make the template-file utilities safe to use as the generator's filesystem boundary. Today they create or truncate the destination before template execution, discard execution errors, and treat symlinks or regular files as output directories. A bad render can therefore destroy an existing file or publish partial output, while callers cannot tell that the operation failed.
Keep the existing parameter lists of TemplateFileAndOverwrite and TemplateFileIfDoesNotExist, but have each return a receive-only <-chan error. Existing statement-style calls that ignore the result must remain source-compatible. Every invocation returns its own non-nil channel, reports exactly one terminal value, and then closes it. The value is nil for a successful write and for an intentional create-only skip, and non-nil for validation, directory, or rendering failures. Once the supplied wait group has finished, the result must already be readable and the channel closed; ignoring the result channel must not prevent wait-group completion. Multiple invocations sharing a wait group must not share results or let one render's error affect another.
Render before publishing. During template execution an overwrite destination must still contain its old bytes, and a new destination must not exist yet. Only a fully successful render may be published. A successful overwrite preserves the destination's existing permission bits; a newly created file uses 0644 permissions. If execution emits some bytes and then returns an error, propagate an error containing the underlying reason, leave an existing destination's bytes and permissions unchanged, leave an absent destination absent, and clean up any temporary artifacts in the output directory. TemplateFileIfDoesNotExist must continue to skip an existing destination without executing its template and report nil.
Treat fileName as a basename, not another path. Both helpers must reject empty names, ., .., absolute names, or names containing a platform path separator, without changing the filesystem. Output directories must be real directories: do not follow a symlink used as fileDir or anywhere in its existing ancestor chain, and reject an existing non-directory. Apply the same directory safety to CreateDirIfDoesNotExist: it may create missing real nested directories and accept an existing real directory, but it must return an error for a symlink target, a symlinked ancestor, or an existing non-directory, without modifying the symlink target. The template helpers surface these directory failures through their completion channels rather than panicking or publishing output.