summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-07-29 18:13:23 +0800
committerKeuin <[email protected]>2023-07-29 20:16:25 +0800
commitcca3c828e0a12ab31ee928a82e672082be642d01 (patch)
tree8e79451a949372c3444f50164cd83264764964a0
parent7153cf3e4288d4395c984e6648df9bafdc4e833f (diff)
Create if save directory does not exist
-rw-r--r--recording/runner.go11
1 files changed, 11 insertions, 0 deletions
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