MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Compress

Method Compress

agent/app/service/file.go:426–465  ·  view source on GitHub ↗
(c request.FileCompress)

Source from the content-addressed store, hash-verified

424}
425
426func (f *FileService) Compress(c request.FileCompress) error {
427 fo := files.NewFileOp()
428 if !c.Replace && fo.Stat(filepath.Join(c.Dst, c.Name)) {
429 return buserr.New("ErrFileIsExist")
430 }
431 if err := preflightCompressTool(files.CompressType(c.Type)); err != nil {
432 return err
433 }
434 taskItem, err := task.NewTask(c.Name, task.TaskExec, task.TaskScopeTask, c.TaskID, 1)
435 if err != nil {
436 return err
437 }
438 go func() {
439 taskItem.AddSubTask(c.Name, func(t *task.Task) error {
440 t.LogStart(c.Name)
441 compressType := files.CompressType(c.Type)
442 dstFile := filepath.Join(c.Dst, c.Name)
443 success := false
444 defer func() {
445 if !success {
446 _ = os.Remove(dstFile)
447 }
448 }()
449 if err := fo.Compress(t.TaskCtx, c.Files, c.Dst, c.Name, compressType, c.Secret, nil); err != nil {
450 return err
451 }
452 info, err := os.Stat(dstFile)
453 if err != nil {
454 return err
455 }
456 if info.Size() == 0 {
457 return fmt.Errorf("compressed file not generated: %s", dstFile)
458 }
459 success = true
460 return nil
461 }, nil)
462 _ = taskItem.Execute()
463 }()
464 return nil
465}
466
467func preflightCompressTool(compressType files.CompressType) error {
468 switch compressType {

Callers

nothing calls this directly

Calls 7

StatMethod · 0.95
AddSubTaskMethod · 0.95
CompressMethod · 0.95
ExecuteMethod · 0.95
preflightCompressToolFunction · 0.85
SizeMethod · 0.65
LogStartMethod · 0.45

Tested by

no test coverage detected