pub fn ensure_file_exists_or_download_http(
filepath: &Path,
url: &str,
checksums: Option<&Path>,
timeout_secs: Option<u64>,
) -> Result<()>Expand description
Ensures that a file exists at the specified path by downloading it if necessary.
If the file already exists, it checks the integrity of the file using a SHA-256 checksum
from the optional checksums file. If the checksum is valid, the function exits early. If
the checksum is invalid or missing, the function updates the checksums file with the correct
hash for the existing file without redownloading it.
If the file does not exist, it downloads the file from the specified url and updates the
checksums file (if provided) with the calculated SHA-256 checksum of the downloaded file.
The timeout_secs parameter specifies the timeout in seconds for the HTTP request.
If None is provided, a default timeout of 30 seconds will be used.
ยงErrors
Returns an error if:
- The HTTP request cannot be sent or returns a non-success status code.
- Any I/O operation fails during file creation, reading, or writing.
- Checksum verification or JSON parsing fails.