Add local source publication
This commit is contained in:
54
internal/publish/output.go
Normal file
54
internal/publish/output.go
Normal file
@@ -0,0 +1,54 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user