feat: delete firmware

This commit is contained in:
2025-10-22 21:14:07 +02:00
parent 4a11bad7dd
commit 6ed905b9f3
6 changed files with 163 additions and 0 deletions

View File

@@ -55,3 +55,20 @@ func (fs *FileStorage) FirmwareExists(name, version string) bool {
_, err := os.Stat(filePath)
return !os.IsNotExist(err)
}
// DeleteFirmwareBinary deletes a firmware binary and its directory
func (fs *FileStorage) DeleteFirmwareBinary(name, version string) error {
// Get directory path: registry/<name>/<version>/
dirPath := filepath.Join(fs.registryPath, name, version)
// Remove the entire version directory
if err := os.RemoveAll(dirPath); err != nil {
return fmt.Errorf("failed to delete firmware directory: %w", err)
}
// Try to remove the name directory if it's empty
nameDir := filepath.Join(fs.registryPath, name)
os.Remove(nameDir) // Ignore error, directory might not be empty
return nil
}