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

Method checkBackupConn

agent/app/service/backup.go:347–380  ·  view source on GitHub ↗
(backup *model.BackupAccount)

Source from the content-addressed store, hash-verified

345}
346
347func (u *BackupService) checkBackupConn(backup *model.BackupAccount) (bool, error) {
348 client, err := newClient(backup, false)
349 if err != nil {
350 return false, err
351 }
352 fileItem := path.Join(global.Dir.BaseDir, "1panel/tmp/test/1panel")
353 if _, err := os.Stat(path.Dir(fileItem)); err != nil && os.IsNotExist(err) {
354 if err = os.MkdirAll(path.Dir(fileItem), os.ModePerm); err != nil {
355 return false, err
356 }
357 }
358 file, err := os.OpenFile(fileItem, os.O_WRONLY|os.O_CREATE, constant.FilePerm)
359 if err != nil {
360 return false, err
361 }
362 defer file.Close()
363 write := bufio.NewWriter(file)
364 _, _ = write.WriteString("1Panel 备份账号测试文件。\n")
365 _, _ = write.WriteString("1Panel 備份賬號測試文件。\n")
366 _, _ = write.WriteString("1Panel Backs up account test files.\n")
367 _, _ = write.WriteString("1Panelアカウントのテストファイルをバックアップします。\n")
368 write.Flush()
369
370 targetPath := path.Join(backup.BackupPath, "test/1panel")
371 if backup.Type != constant.Sftp && backup.Type != constant.Local && targetPath != "/" {
372 targetPath = strings.TrimPrefix(targetPath, "/")
373 }
374
375 if _, err := client.Upload(fileItem, targetPath); err != nil {
376 return false, err
377 }
378 _, _ = client.Delete(path.Join(backup.BackupPath, "test/1panel"))
379 return true, nil
380}
381
382func (u *BackupService) LoadBackupOptions() ([]dto.BackupOption, error) {
383 accounts, err := backupRepo.List(repo.WithOrderDesc("created_at"))

Callers 1

CheckConnMethod · 0.95

Calls 8

newClientFunction · 0.85
MkdirAllMethod · 0.80
OpenFileMethod · 0.80
CloseMethod · 0.65
UploadMethod · 0.65
DeleteMethod · 0.65
StatMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected