mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-30 22:23:53 +00:00
[v12.0/forgejo] fix: follow symlinks for local assets (#8610)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8596 - This reverts behavior that was partially unintentionally introduced in forgejo/forgejo#8143, symbolic links were no longer followed (if they escaped the asset folder) for local assets. - Having symbolic links for user-added files is, to my understanding, a ,common usecase for NixOS and would thus have symbolic links in the asset folders. Avoiding symbolic links is not easy. - The previous code used `http.Dir`, we cannot use that as it's not of the same type. The equivalent is `os.DirFS`. - Unit test to prevent this regression from happening again. Reported-by: bloxx12 (Matrix). Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8610 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
9d47719545
commit
4819d4a29a
2 changed files with 30 additions and 9 deletions
|
@ -56,14 +56,7 @@ func Local(name, base string, sub ...string) *Layer {
|
|||
panic(fmt.Sprintf("Unable to get absolute path for %q: %v", base, err))
|
||||
}
|
||||
root := util.FilePathJoinAbs(base, sub...)
|
||||
fsRoot, err := os.OpenRoot(root)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
panic(fmt.Sprintf("Unable to open layer %q", err))
|
||||
}
|
||||
return &Layer{name: name, fs: fsRoot.FS(), localPath: root}
|
||||
return &Layer{name: name, fs: os.DirFS(root), localPath: root}
|
||||
}
|
||||
|
||||
// Bindata returns a new Layer with the given name, it serves files from the given bindata asset.
|
||||
|
@ -80,7 +73,7 @@ type LayeredFS struct {
|
|||
|
||||
// Layered returns a new LayeredFS with the given layers. The first layer is the top layer.
|
||||
func Layered(layers ...*Layer) *LayeredFS {
|
||||
return &LayeredFS{layers: slices.DeleteFunc(layers, func(layer *Layer) bool { return layer == nil })}
|
||||
return &LayeredFS{layers: layers}
|
||||
}
|
||||
|
||||
// Open opens the named file. The caller is responsible for closing the file.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue