First pass at full fork pretty much complete.

This commit is contained in:
Storm Dragon
2026-05-20 14:29:39 -04:00
parent 6275e3adef
commit e257b344d1
11 changed files with 307 additions and 19 deletions
+51
View File
@@ -34,6 +34,8 @@ const (
var Directory string
var activeRecordings sync.Map
type Client struct {
hall *hall.Hall
id string
@@ -250,6 +252,7 @@ func newRecorder(client *Client, directory string) (*recorder, error) {
done: make(chan error, 1),
sources: make(map[*diskTrack]chan []byte),
}
activeRecordings.Store(path, struct{}{})
go r.mix()
return r, nil
}
@@ -358,6 +361,7 @@ func (r *recorder) Close() error {
err := <-r.done
stdinErr := r.stdin.Close()
waitErr := r.cmd.Wait()
activeRecordings.Delete(r.path)
if err != nil {
return err
@@ -368,6 +372,10 @@ func (r *recorder) Close() error {
if waitErr != nil {
return waitErr
}
now := time.Now()
if err := os.Chtimes(r.path, now, now); err != nil {
return err
}
return nil
}
@@ -658,6 +666,49 @@ func openDiskFile(directory, extension string) (*os.File, error) {
return nil, errors.New("couldn't create file")
}
func CleanupOldRecordings(retention time.Duration) error {
if retention <= 0 {
return nil
}
cutoff := time.Now().Add(-retention)
err := filepath.WalkDir(
Directory,
func(path string, d os.DirEntry, err error) error {
if err != nil {
log.Printf("Recording cleanup %v: %v", path, err)
return nil
}
if d.IsDir() {
return nil
}
name := d.Name()
if !strings.HasPrefix(name, "skald-recording-") ||
filepath.Ext(name) != ".ogg" {
return nil
}
if _, ok := activeRecordings.Load(path); ok {
return nil
}
info, err := d.Info()
if err != nil {
log.Printf("Recording cleanup %v: %v", path, err)
return nil
}
if info.ModTime().After(cutoff) {
return nil
}
if err := os.Remove(path); err != nil {
log.Printf("Recording cleanup %v: %v", path, err)
}
return nil
},
)
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}
func drainStderr(prefix string, r io.Reader) {
buf := make([]byte, 1024)
for {