MCPcopy
hub / github.com/safing/portmaster / PutMany

Method PutMany

base/database/interface.go:354–444  ·  view source on GitHub ↗

PutMany stores many records in the database. Warning: This is nearly a direct database access and omits many things: - Record locking - Hooks - Subscriptions - Caching Use with care.

(dbName string)

Source from the content-addressed store, hash-verified

352// - Caching
353// Use with care.
354func (i *Interface) PutMany(dbName string) (put func(record.Record) error) {
355 interfaceBatch := make(chan record.Record, 100)
356
357 // permission check
358 if !i.options.HasAllPermissions() {
359 return func(r record.Record) error {
360 return ErrPermissionDenied
361 }
362 }
363
364 // get database
365 db, err := getController(dbName)
366 if err != nil {
367 return func(r record.Record) error {
368 return err
369 }
370 }
371
372 // Check if database is read only.
373 if db.ReadOnly() {
374 return func(r record.Record) error {
375 return ErrReadOnly
376 }
377 }
378
379 // start database access
380 dbBatch, errs := db.PutMany()
381 finished := abool.New()
382 var internalErr error
383
384 // interface options proxy
385 go func() {
386 defer close(dbBatch) // signify that we are finished
387 for {
388 select {
389 case r := <-interfaceBatch:
390 // finished?
391 if r == nil {
392 return
393 }
394 // apply options
395 i.options.Apply(r)
396 // pass along
397 dbBatch <- r
398 case <-time.After(1 * time.Second):
399 // bail out
400 internalErr = errors.New("timeout: putmany unused for too long")
401 finished.Set()
402 return
403 }
404 }
405 }()
406
407 return func(r record.Record) error {
408 // finished?
409 if finished.IsSet() {
410 // check for internal error
411 if internalErr != nil {

Callers 4

persistRecordsFunction · 0.95
DelayedCacheWriterMethod · 0.95
flushWriteCacheMethod · 0.95
testDatabaseFunction · 0.95

Calls 9

getControllerFunction · 0.85
HasAllPermissionsMethod · 0.80
NewMethod · 0.80
ReadOnlyMethod · 0.65
PutManyMethod · 0.65
ApplyMethod · 0.65
SetMethod · 0.65
DatabaseNameMethod · 0.65
IsSetMethod · 0.45

Tested by 1

testDatabaseFunction · 0.76