MCPcopy
hub / github.com/wavetermdev/waveterm / HandleTruncateBlockFile

Function HandleTruncateBlockFile

pkg/blockcontroller/blockcontroller.go:391–419  ·  view source on GitHub ↗
(blockId string)

Source from the content-addressed store, hash-verified

389}
390
391func HandleTruncateBlockFile(blockId string) error {
392 ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
393 defer cancelFn()
394 err := filestore.WFS.WriteFile(ctx, blockId, wavebase.BlockFile_Term, nil)
395 if err == fs.ErrNotExist {
396 return nil
397 }
398 if err != nil {
399 return fmt.Errorf("error truncating blockfile: %w", err)
400 }
401 err = filestore.WFS.DeleteFile(ctx, blockId, wavebase.BlockFile_Cache)
402 if err == fs.ErrNotExist {
403 err = nil
404 }
405 if err != nil {
406 log.Printf("error deleting cache file (continuing): %v\n", err)
407 }
408 wps.Broker.Publish(wps.WaveEvent{
409 Event: wps.Event_BlockFile,
410 Scopes: []string{waveobj.MakeORef(waveobj.OType_Block, blockId).String()},
411 Data: &wps.WSFileEventData{
412 ZoneId: blockId,
413 FileName: wavebase.BlockFile_Term,
414 FileOp: wps.FileOp_Truncate,
415 },
416 })
417 return nil
418
419}
420
421func debugLog(ctx context.Context, fmtStr string, args ...interface{}) {
422 blocklogger.Infof(ctx, "[conndebug] "+fmtStr, args...)

Callers 1

runMethod · 0.85

Calls 5

MakeORefFunction · 0.92
WriteFileMethod · 0.80
DeleteFileMethod · 0.80
PublishMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected