Skip to content

Commit 1c9df09

Browse files
committed
fixup dbmem to return unique files error
1 parent 4ec22d8 commit 1c9df09

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8743,6 +8743,12 @@ func (q *FakeQuerier) InsertFile(_ context.Context, arg database.InsertFileParam
87438743
q.mutex.Lock()
87448744
defer q.mutex.Unlock()
87458745

8746+
if slices.ContainsFunc(q.files, func(file database.File) bool {
8747+
return file.CreatedBy == arg.CreatedBy && file.Hash == arg.Hash
8748+
}) {
8749+
return database.File{}, newUniqueConstraintError(database.UniqueFilesHashCreatedByKey)
8750+
}
8751+
87468752
//nolint:gosimple
87478753
file := database.File{
87488754
ID: arg.ID,

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ UploadFileStream:
14011401
return xerrors.Errorf("insert file: %w", err)
14021402
}
14031403
}
1404+
14041405
s.Logger.Info(s.lifecycleCtx, "file uploaded to database",
14051406
slog.F("type", file.Type.String()),
14061407
slog.F("hash", hash),

0 commit comments

Comments
 (0)