55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package publish
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/state"
|
|
"gitea.maximumdirect.net/eric/distributor/internal/storage"
|
|
)
|
|
|
|
func PlanSourceOutputs(req Request) ([]Output, error) {
|
|
if !req.Publish.Source {
|
|
return nil, nil
|
|
}
|
|
outputs := make([]Output, 0, len(req.SourceBundle.Manifest.Files))
|
|
seen := make(map[string]struct{}, len(req.SourceBundle.Manifest.Files))
|
|
for _, file := range req.SourceBundle.Manifest.Files {
|
|
if _, exists := seen[file.Path]; exists {
|
|
return nil, fmt.Errorf("destination output path collision: %s", file.Path)
|
|
}
|
|
seen[file.Path] = struct{}{}
|
|
if err := storage.ValidatePath(file.Path); err != nil {
|
|
return nil, fmt.Errorf("destination output path %q: %w", file.Path, err)
|
|
}
|
|
outputs = append(outputs, Output{
|
|
SourcePath: file.Path,
|
|
DestinationPath: file.Path,
|
|
SHA256: file.SHA256,
|
|
Size: file.Size,
|
|
})
|
|
}
|
|
return outputs, nil
|
|
}
|
|
|
|
func stateOutputs(outputs []Output) []state.OutputFile {
|
|
files := make([]state.OutputFile, 0, len(outputs))
|
|
for _, output := range outputs {
|
|
files = append(files, state.OutputFile{
|
|
Path: output.DestinationPath,
|
|
Kind: state.OutputKindSource,
|
|
SourcePath: output.SourcePath,
|
|
SHA256: output.SHA256,
|
|
Size: output.Size,
|
|
})
|
|
}
|
|
return files
|
|
}
|
|
|
|
func managedOutputPaths(outputs []Output) []string {
|
|
paths := make([]string, 0, len(outputs))
|
|
for _, output := range outputs {
|
|
paths = append(paths, output.DestinationPath)
|
|
}
|
|
return paths
|
|
}
|