feat: restart to apply update, privileged helper, rollback
This commit is contained in:
1 parent
70460e4170
commit
54e8fd5fed
63 files changed
+8635
-164
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package update
|
||||
|
||||
import (
|
||||
domain "RenewCMS/internal/domain/update"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type JSONRestartRequestStore struct {
|
||||
path string
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var _ domain.RestartRequestStore = &JSONRestartRequestStore{}
|
||||
|
||||
func NewJSONRestartRequestStore(path string) *JSONRestartRequestStore {
|
||||
return &JSONRestartRequestStore{path: path}
|
||||
}
|
||||
|
||||
func (s *JSONRestartRequestStore) Write(request domain.RestartRequest) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
return writeJSONAtomically(s.path, request, statusFilePermissions)
|
||||
}
|
||||
|
||||
func (s *JSONRestartRequestStore) Read() (domain.RestartRequest, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
info, err := os.Lstat(s.path)
|
||||
if errors.Is(err, fs.ErrNotExist) || (err == nil && info.IsDir()) {
|
||||
return domain.RestartRequest{}, domain.ErrNoRestartRequest
|
||||
}
|
||||
if err != nil {
|
||||
return domain.RestartRequest{}, err
|
||||
}
|
||||
content, err := os.ReadFile(s.path)
|
||||
if err != nil {
|
||||
return domain.RestartRequest{}, err
|
||||
}
|
||||
var request domain.RestartRequest
|
||||
return request, json.Unmarshal(content, &request)
|
||||
}
|
||||
|
||||
func (s *JSONRestartRequestStore) Delete() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
return removeIfPresent(s.path)
|
||||
}
|
||||
Reference in new issue
Block a user