Add resumable downloads, download paths, queue controls and history
This commit is contained in:
1 parent
434f6441da
commit
6027cfabb9
43 files changed
+2138
-291
No files matched your search
@@ -6,9 +6,10 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"ddc/internal/files"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
@@ -47,6 +48,10 @@ func (store *Store) Get() Preferences {
|
||||
if current.AllowedPorts == nil {
|
||||
current.AllowedPorts = []uint16{}
|
||||
}
|
||||
current.DownloadPaths = slices.Clone(current.DownloadPaths)
|
||||
if current.DownloadPaths == nil {
|
||||
current.DownloadPaths = []string{}
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
@@ -61,27 +66,9 @@ func (store *Store) Update(next Preferences) error {
|
||||
|
||||
store.mutex.Lock()
|
||||
defer store.mutex.Unlock()
|
||||
if err := writeAtomically(store.path, data); err != nil {
|
||||
if err := files.WriteAtomically(store.path, data); err != nil {
|
||||
return err
|
||||
}
|
||||
store.current = next
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeAtomically(path string, data []byte) error {
|
||||
temporary, err := os.CreateTemp(filepath.Dir(path), ".settings-*.tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, writeErr := temporary.Write(data)
|
||||
closeErr := temporary.Close()
|
||||
if writeErr != nil || closeErr != nil {
|
||||
os.Remove(temporary.Name())
|
||||
return errors.Join(writeErr, closeErr)
|
||||
}
|
||||
if err := os.Rename(temporary.Name(), path); err != nil {
|
||||
os.Remove(temporary.Name())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user