From cca3c828e0a12ab31ee928a82e672082be642d01 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 18:13:23 +0800 Subject: Create if save directory does not exist --- recording/runner.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'recording') diff --git a/recording/runner.go b/recording/runner.go index c724735..9ef2cfd 100644 --- a/recording/runner.go +++ b/recording/runner.go @@ -333,6 +333,17 @@ func record( writeBufferSize := task.Download.DiskWriteBufferBytes logger.Info("Write buffer size: %v byte", writeBufferSize) err = bi.CopyLiveStream(ctx, task.RoomId, streamSource, func() (f *os.File, e error) { + dirInfo, err := os.Stat(saveDir) + if err != nil && !errors.Is(err, os.ErrNotExist) { + return nil, err + } + err = nil + if dirInfo == nil || !dirInfo.IsDir() { + err = os.Mkdir(saveDir, 0775) + if err != nil { + return nil, fmt.Errorf("cannot create save directory: %w", err) + } + } f, e = os.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) if e != nil { file = f -- cgit v1.2.3