Skip to content

Commit fb8c284

Browse files
committed
select file by hash
1 parent 931ac95 commit fb8c284

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
773773
case database.ProvisionerStorageMethodFile:
774774
file, err := s.Database.GetFileByID(ctx, job.FileID)
775775
if err != nil {
776-
return nil, failJob(fmt.Sprintf("get file by hash: %s", err))
776+
return nil, failJob(fmt.Sprintf("get file by id: %s", err))
777777
}
778778
protoJob.TemplateSourceArchive = file.Data
779779
default:
@@ -1399,6 +1399,7 @@ UploadFileStream:
13991399
return xerrors.Errorf("insert file: %w", err)
14001400
}
14011401
}
1402+
14021403
return nil
14031404
}
14041405

@@ -1687,6 +1688,19 @@ func (s *server) completeTemplateImportJob(ctx context.Context, job database.Pro
16871688
}
16881689
}
16891690

1691+
if len(jobType.TemplateImport.ModuleFilesHash) > 0 {
1692+
hashString := hex.EncodeToString(jobType.TemplateImport.ModuleFilesHash)
1693+
file, err := db.GetFileByHashAndCreator(dbauthz.AsSystemRestricted(ctx), database.GetFileByHashAndCreatorParams{Hash: hashString, CreatedBy: uuid.Nil})
1694+
if err != nil {
1695+
return xerrors.Errorf("get file by hash, it should have been uploaded: %w", err)
1696+
}
1697+
1698+
fileID = uuid.NullUUID{
1699+
Valid: true,
1700+
UUID: file.ID,
1701+
}
1702+
}
1703+
16901704
err = db.InsertTemplateVersionTerraformValuesByJobID(ctx, database.InsertTemplateVersionTerraformValuesByJobIDParams{
16911705
JobID: jobID,
16921706
UpdatedAt: now,

provisionerd/provisionerd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provisionerd
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"errors"
67
"fmt"
78
"io"
@@ -570,9 +571,11 @@ func (p *Server) CompleteJob(ctx context.Context, in *proto.CompletedJob) error
570571
if messageSize > drpcsdk.MaxMessageSize &&
571572
messageSize-len(ti.TemplateImport.ModuleFiles) < drpcsdk.MaxMessageSize {
572573

574+
moduleFilesHash := sha256.Sum256(ti.TemplateImport.ModuleFiles)
573575
// Split the module files from the message if it exceeds the max size.
574576
moduleFiles := ti.TemplateImport.ModuleFiles
575577
ti.TemplateImport.ModuleFiles = nil // Clear the files in the final message
578+
ti.TemplateImport.ModuleFilesHash = moduleFilesHash[:]
576579
err := p.UploadModuleFiles(ctx, moduleFiles)
577580
if err != nil {
578581
return err

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy