Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
985d2475dc |
16
update.go
16
update.go
@ -11,6 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gokrazy/internal/fat"
|
"github.com/gokrazy/internal/fat"
|
||||||
"github.com/gokrazy/internal/rootdev"
|
"github.com/gokrazy/internal/rootdev"
|
||||||
|
"github.com/klauspost/compress/zstd"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootRe = regexp.MustCompile(`root=[^ ]+`)
|
var rootRe = regexp.MustCompile(`root=[^ ]+`)
|
||||||
@ -100,7 +102,17 @@ func nonConcurrentUpdateHandler(dest string) func(http.ResponseWriter, *http.Req
|
|||||||
default:
|
default:
|
||||||
hash = sha256.New()
|
hash = sha256.New()
|
||||||
}
|
}
|
||||||
if err := streamRequestTo(dest, io.TeeReader(r.Body, hash)); err != nil {
|
rd := io.Reader(r.Body)
|
||||||
|
if strings.EqualFold(r.Header.Get("Content-Encoding"), "zstd") {
|
||||||
|
dec, err := zstd.NewReader(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("updating %q failed: %v", dest, err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rd = dec
|
||||||
|
}
|
||||||
|
if err := streamRequestTo(dest, io.TeeReader(rd, hash)); err != nil {
|
||||||
log.Printf("updating %q failed: %v", dest, err)
|
log.Printf("updating %q failed: %v", dest, err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -133,7 +145,7 @@ func initUpdate() error {
|
|||||||
// feature support (e.g. PARTUUID= support) between the packer and update
|
// feature support (e.g. PARTUUID= support) between the packer and update
|
||||||
// target.
|
// target.
|
||||||
http.HandleFunc("/update/features", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/update/features", func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "partuuid,updatehash,")
|
fmt.Fprintf(w, "partuuid,updatehash,zstd,")
|
||||||
})
|
})
|
||||||
http.HandleFunc("/update/mbr", nonConcurrentUpdateHandler(rootdev.BlockDevice()))
|
http.HandleFunc("/update/mbr", nonConcurrentUpdateHandler(rootdev.BlockDevice()))
|
||||||
http.HandleFunc("/update/root", nonConcurrentUpdateHandler(rootdev.Partition(rootdev.InactiveRootPartition())))
|
http.HandleFunc("/update/root", nonConcurrentUpdateHandler(rootdev.Partition(rootdev.InactiveRootPartition())))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user