Replace a destination with a prepared file while retaining its mode.

SolidGroundUX DocumentationSolidGroundUX
NL

fn: sgnd_safe_replace_file

Purpose

Replace a destination with a prepared file while retaining its mode.

Arguments

  • $1 — Prepared source file.
  • $2 — Existing destination file.

Side effects

Copies the destination file mode onto the source and moves it over the destination.

Returns

  • 0 when moved; 1 if either file is absent or chmod/mv fails.

Usage

  sgnd_safe_replace_file "$temp_file" "$config_file"