Skip to main content

Module file_output

Module file_output 

Source
Expand description

Shared helpers for writing command output to files.

Ports the legacy CLIโ€™s CliUtils.saveFile / CliUtils.saveResultToFile (apps/cli/src/utils.ts) path-resolution rules, which are part of the user-facing contract for every flag that takes an output location (bw receive --obj, bw export --output, bw get attachment --output). Kept separate from the commands themselves so those rules are defined โ€” and tested โ€” exactly once.

Functionsยง

contains_separator ๐Ÿ”’
true when output contains a path separator. Windows accepts both \ and /, and Rustโ€™s Path treats both as separators there, so both are checked rather than just std::path::MAIN_SEPARATOR.
create_dir_all_private ๐Ÿ”’
Create dir and its missing parents, owner-only on unix (legacy creates them 700).
default_send_file_name ๐Ÿ”’
Derive the file name to save a received Sendโ€™s file under.
ends_with_separator ๐Ÿ”’
reject_path_traversal ๐Ÿ”’
Reject paths containing a .. segment before they reach the filesystem: a script that forwards an unsanitized path through to this CLI should not be able to resolve outside the directory it intended, even though bw itself only ever reads and writes with the invoking userโ€™s own permissions.
resolve_output_path ๐Ÿ”’
Resolve where to write a commandโ€™s file output, porting CliUtils.saveFileโ€™s rules exactly:
save_file ๐Ÿ”’
Write data to the location resolve_output_path picks for (output, default_file_name) and return the path written, so the caller can report it back to the user.
write_file_private ๐Ÿ”’
Write data to path, owner-only on unix (legacy writes 0o600).