MCPcopy
hub / github.com/daptin/daptin / CreateDefaultLocalStorage

Function CreateDefaultLocalStorage

server/resource/storage.go:13–108  ·  view source on GitHub ↗
(transaction *sqlx.Tx, localStoragePath string)

Source from the content-addressed store, hash-verified

11)
12
13func CreateDefaultLocalStorage(transaction *sqlx.Tx, localStoragePath string) error {
14 log.Tracef("CreateDefaultLocalStorage")
15 query, vars, err := statementbuilder.Squirrel.Select("reference_id").Prepared(true).From("cloud_store").
16 Where(goqu.Ex{
17 "name": "localstore",
18 }).ToSQL()
19
20 if err != nil {
21 return err
22 }
23
24 stmt1, err := transaction.Preparex(query)
25 if err != nil {
26 log.Errorf("[26] failed to prepare statment: %v", err)
27 return err
28 }
29 defer func(stmt1 *sqlx.Stmt) {
30 err := stmt1.Close()
31 if err != nil {
32 log.Errorf("failed to close prepared statement: %v", err)
33 }
34 }(stmt1)
35
36 res := stmt1.QueryRow(vars...)
37 var storageReferenceId string
38 err = res.Scan(&storageReferenceId)
39 stmt1.Close()
40 if err != nil {
41 if err == sql.ErrNoRows {
42
43 adminUserId, adminGroupId := GetAdminUserIdAndUserGroupId(transaction)
44 newUuid, _ := uuid.NewV7()
45 query, vars, err = statementbuilder.Squirrel.Insert("cloud_store").Prepared(true).
46 Cols("reference_id", "name", "store_type", "store_provider", "root_path", "store_parameters", "user_account_id", "permission").
47 Vals([]interface{}{newUuid[:], "localstore", "local", "local", localStoragePath, "", adminUserId, auth.DEFAULT_PERMISSION}).ToSQL()
48
49 if err != nil {
50 return err
51 }
52
53 _, err = transaction.Exec(query, vars...)
54 if err != nil {
55 return err
56 }
57
58 query, vars, err = statementbuilder.Squirrel.Select("id").From("cloud_store").Prepared(true).
59 Where(goqu.Ex{
60 "reference_id": newUuid[:],
61 }).ToSQL()
62 if err != nil {
63 return err
64 }
65
66 stmt1, err := transaction.Preparex(query)
67 if err != nil {
68 log.Errorf("[67] failed to prepare statment: %v", err)
69 }
70 defer func(stmt1 *sqlx.Stmt) {

Callers 1

MainFunction · 0.92

Calls 9

ScanMethod · 0.80
ExecMethod · 0.80
QueryRowxMethod · 0.80
ErrMethod · 0.80
SelectMethod · 0.65
PreparexMethod · 0.65
CloseMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected