Ensure a path ends with the appropriate extension for the format.
(path: &Path, format: ArchiveFormat)
| 804 | |
| 805 | /// Ensure a path ends with the appropriate extension for the format. |
| 806 | pub fn ensure_extension(path: &Path, format: ArchiveFormat) -> PathBuf { |
| 807 | let ext = format.extension(); |
| 808 | if ext.is_empty() { |
| 809 | return path.to_path_buf(); |
| 810 | } |
| 811 | |
| 812 | let path_str = path.to_string_lossy(); |
| 813 | if path_str.ends_with(ext) { |
| 814 | path.to_path_buf() |
| 815 | } else { |
| 816 | PathBuf::from(format!("{}{}", path_str, ext)) |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /// Get the output path for an archive with optional prefix. |
| 821 | pub fn get_archive_path(base: &Path, prefix: Option<&str>) -> PathBuf { |