MCPcopy Index your code
hub / github.com/dnote/dnote / resolveLabel

Function resolveLabel

pkg/cli/cmd/sync/sync.go:250–267  ·  view source on GitHub ↗

resolveLabel resolves a book label conflict by repeatedly appending an increasing integer to the label until it finds a unique label. It returns the first non-conflicting label.

(tx *database.DB, label string)

Source from the content-addressed store, hash-verified

248// resolveLabel resolves a book label conflict by repeatedly appending an increasing integer
249// to the label until it finds a unique label. It returns the first non-conflicting label.
250func resolveLabel(tx *database.DB, label string) (string, error) {
251 var ret string
252
253 for i := 2; ; i++ {
254 ret = fmt.Sprintf("%s_%d", label, i)
255
256 var cnt int
257 if err := tx.QueryRow("SELECT count(*) FROM books WHERE label = ?", ret).Scan(&cnt); err != nil {
258 return "", errors.Wrapf(err, "checking availability of label %s", ret)
259 }
260
261 if cnt == 0 {
262 break
263 }
264 }
265
266 return ret, nil
267}
268
269// mergeBook inserts or updates the given book in the local database.
270// If a book with a duplicate label exists locally, it renames the duplicate by appending a number.

Callers 2

mergeBookFunction · 0.85
TestResolveLabelFunction · 0.85

Calls 1

QueryRowMethod · 0.65

Tested by 1

TestResolveLabelFunction · 0.68