files

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupDownloadedIcon

func CleanupDownloadedIcon(webSource, filePath string)

CleanupDownloadedIcon handles the cleanup of downloaded icon files from web sources. It ensures files are only deleted if they were downloaded from HTTP(s) sources and are in the temporary directory.

func CleanupDownloadedPackage

func CleanupDownloadedPackage(packageFileSource, localFilePath string)

CleanupDownloadedPackage handles the cleanup of downloaded package files from web sources. It ensures files are only deleted if they were downloaded from HTTP(s) sources and are in the temporary directory.

func DownloadFile

func DownloadFile(url string) (string, error)

DownloadFile downloads a file from a URL and saves it to a temporary directory with security validation. It follows redirects up to a maximum of 10 times. The filename is determined in the following order: 1. From Content-Disposition header if present and valid 2. From the final URL after redirects if valid 3. Falls back to a timestamp-based name if both sources are invalid

The function implements several security measures: - Validates filenames to prevent directory traversal - Restricts filenames to alphanumeric characters, dots, hyphens, underscores, and spaces - Replaces '%' characters with '_' - Ensures final path remains within temporary directory - Verifies path safety after normalization

Returns the path to the downloaded file and any error encountered. Possible errors include: - Failed to create temporary file - Too many redirects - Download failure - Write failure - Invalid filename - Path traversal attempt - Rename failure

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL