Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
🧖‍♀️
  • Loading branch information
aslilac committed May 13, 2025
commit fdd6a43d9809660f828c2545dd3e6d65cdaf8301
26 changes: 8 additions & 18 deletions coderd/files/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,25 @@ func NewOverlayFS(baseFS fs.FS, overlays []Overlay) fs.FS {
}
}

func (f overlayFS) Open(p string) (fs.File, error) {
func (f overlayFS) target(p string) fs.FS {
target := f.baseFS
for _, overlay := range f.overlays {
if strings.HasPrefix(path.Clean(p), overlay.Path) {
target = overlay.FS
break
}
}
return target.Open(p)
return target
}

func (f overlayFS) Open(p string) (fs.File, error) {
return f.target(p).Open(p)
}

func (f overlayFS) ReadDir(p string) ([]fs.DirEntry, error) {
target := f.baseFS
for _, overlay := range f.overlays {
if strings.HasPrefix(path.Clean(p), overlay.Path) {
target = overlay.FS
break
}
}
return fs.ReadDir(target, p)
return fs.ReadDir(f.target(p), p)
}

func (f overlayFS) ReadFile(p string) ([]byte, error) {
target := f.baseFS
for _, overlay := range f.overlays {
if strings.HasPrefix(path.Clean(p), overlay.Path) {
target = overlay.FS
break
}
}
return fs.ReadFile(target, p)
return fs.ReadFile(f.target(p), p)
}
Loading