flamenco/pkg/shaman/checkout/report_requirements.go
Sybren A. Stüvel 02fac6a4df Change Go package name from git.blender.org to projects.blender.org
Change the package base name of the Go code, from
`git.blender.org/flamenco` to `projects.blender.org/studio/flamenco`.

The old location, `git.blender.org`, has no longer been use since the
[migration to Gitea][1]. The new package names now reflect the actual
location where Flamenco is hosted.

[1]: https://code.blender.org/2023/02/new-blender-development-infrastructure/
2023-08-01 12:42:31 +02:00

74 lines
2.2 KiB
Go

package checkout
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"context"
"fmt"
"projects.blender.org/studio/flamenco/pkg/api"
"projects.blender.org/studio/flamenco/pkg/shaman/filestore"
"github.com/rs/zerolog"
)
func (m *Manager) ReportRequirements(ctx context.Context, requirements api.ShamanRequirementsRequest) (api.ShamanRequirementsResponse, error) {
logger := zerolog.Ctx(ctx)
logger.Debug().Msg("user requested checkout requirements")
missing := api.ShamanRequirementsResponse{
Files: []api.ShamanFileSpecWithStatus{},
}
alreadyRequested := map[string]bool{}
for _, fileSpec := range requirements.Files {
fileKey := fmt.Sprintf("%s/%d", fileSpec.Sha, fileSpec.Size)
if alreadyRequested[fileKey] {
// User asked for this (checksum, filesize) tuple already.
continue
}
storePath, status := m.fileStore.ResolveFile(fileSpec.Sha, int64(fileSpec.Size), filestore.ResolveEverything)
var apiStatus api.ShamanFileStatus
switch status {
case filestore.StatusDoesNotExist:
// Caller can upload this file immediately.
apiStatus = api.ShamanFileStatusUnknown
case filestore.StatusUploading:
// Caller should postpone uploading this file until all 'unknown' files have been uploaded.
apiStatus = api.ShamanFileStatusUploading
case filestore.StatusStored:
// We expect this file to be sent soon, though, so we need to
// 'touch' it to make sure it won't be GC'd in the mean time.
go func() {
if err := touchFile(storePath); err != nil {
logger.Error().Err(err).Str("path", storePath).Msg("shaman: error touching file")
}
}()
// Only send a response when the caller needs to do something.
continue
default:
logger.Error().
Str("path", fileSpec.Path).
Str("status", status.String()).
Str("checksum", fileSpec.Sha).
Int("filesize", fileSpec.Size).
Msg("shaman: invalid status returned by ResolveFile, ignoring this file")
continue
}
alreadyRequested[fileKey] = true
fileSpec := api.ShamanFileSpecWithStatus{
Path: fileSpec.Path,
Sha: fileSpec.Sha,
Size: fileSpec.Size,
Status: apiStatus,
}
logger.Trace().Interface("fileSpec", fileSpec).Msg("shaman: file needed from client")
missing.Files = append(missing.Files, fileSpec)
}
return missing, nil
}