forked from rosa/hakurei
internal/rosa: access backing storage through fs
This is more versatile than hardcoding the os.Root implementation. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
+14
-8
@@ -204,7 +204,7 @@ func (r Remote) Status(
|
||||
// NewMirror returns an [http.Handler] for servicing mirror requests.
|
||||
func NewMirror(
|
||||
msg message.Msg,
|
||||
base *os.Root,
|
||||
fsys fs.FS,
|
||||
key ed25519.PrivateKey,
|
||||
) http.Handler {
|
||||
const identName = "ident"
|
||||
@@ -224,7 +224,7 @@ func NewMirror(
|
||||
}
|
||||
|
||||
ids := pkg.Encode((pkg.Checksum)(buf[:len(pkg.Checksum{})]))
|
||||
if linkname, err := base.Readlink(filepath.Join(
|
||||
if linkname, err := fs.ReadLink(fsys, filepath.Join(
|
||||
"identifier",
|
||||
ids,
|
||||
)); err != nil {
|
||||
@@ -239,7 +239,7 @@ func NewMirror(
|
||||
(*pkg.Checksum)(buf[len(pkg.Checksum{}):]),
|
||||
filepath.Base(linkname),
|
||||
); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
msg.Verbosef("serving artifact %s", ids)
|
||||
@@ -276,7 +276,7 @@ func NewMirror(
|
||||
|
||||
checksums := pkg.Encode(buf)
|
||||
rel := filepath.Join("checksum", checksums)
|
||||
if _, err := base.Lstat(rel); err != nil {
|
||||
if _, err := fs.Lstat(fsys, rel); err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
@@ -287,7 +287,7 @@ func NewMirror(
|
||||
}
|
||||
msg.Verbosef("serving outcome %s", pkg.Encode(buf))
|
||||
|
||||
fsys, err := fs.Sub(base.FS(), rel)
|
||||
_fsys, err := fs.Sub(fsys, rel)
|
||||
if err != nil {
|
||||
msg.GetLogger().Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
@@ -301,7 +301,7 @@ func NewMirror(
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
if err = pkg.Write(fsys, ".", gw); err != nil {
|
||||
if err = pkg.Write(_fsys, ".", gw); err != nil {
|
||||
msg.Verbose(err)
|
||||
}
|
||||
if err = gw.Close(); err != nil {
|
||||
@@ -323,7 +323,7 @@ func NewMirror(
|
||||
}
|
||||
|
||||
ids := pkg.Encode((pkg.Checksum)(buf[:len(pkg.Checksum{})]))
|
||||
f, err := base.Open(filepath.Join(
|
||||
f, err := fsys.Open(filepath.Join(
|
||||
"status",
|
||||
ids,
|
||||
))
|
||||
@@ -336,6 +336,12 @@ func NewMirror(
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s, ok := f.(io.Seeker)
|
||||
if !ok {
|
||||
msg.GetLogger().Println("backing filesystem does not support seek")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
msg.Verbosef("serving status %s", ids)
|
||||
|
||||
h := sha512.New384()
|
||||
@@ -348,7 +354,7 @@ func NewMirror(
|
||||
if _, err = w.Write(append(ed25519.Sign(key, buf[:]), buf[:]...)); err != nil {
|
||||
msg.Verbose(err)
|
||||
return
|
||||
} else if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||
} else if _, err = s.Seek(0, io.SeekStart); err != nil {
|
||||
msg.GetLogger().Println(err)
|
||||
return
|
||||
} else if _, err = io.Copy(w, f); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user