mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
@@ -28,12 +28,12 @@ var (
|
||||
type hasBytesFs struct {
|
||||
afero.Fs
|
||||
shouldCheck func(name string) bool
|
||||
hasBytesCallback func(name string, match bool)
|
||||
pattern []byte
|
||||
hasBytesCallback func(name string, match []byte)
|
||||
patterns [][]byte
|
||||
}
|
||||
|
||||
func NewHasBytesReceiver(delegate afero.Fs, shouldCheck func(name string) bool, hasBytesCallback func(name string, match bool), pattern []byte) afero.Fs {
|
||||
return &hasBytesFs{Fs: delegate, shouldCheck: shouldCheck, hasBytesCallback: hasBytesCallback, pattern: pattern}
|
||||
func NewHasBytesReceiver(delegate afero.Fs, shouldCheck func(name string) bool, hasBytesCallback func(name string, match []byte), patterns ...[]byte) afero.Fs {
|
||||
return &hasBytesFs{Fs: delegate, shouldCheck: shouldCheck, hasBytesCallback: hasBytesCallback, patterns: patterns}
|
||||
}
|
||||
|
||||
func (fs *hasBytesFs) UnwrapFilesystem() afero.Fs {
|
||||
@@ -60,10 +60,15 @@ func (fs *hasBytesFs) wrapFile(f afero.File) afero.File {
|
||||
if !fs.shouldCheck(f.Name()) {
|
||||
return f
|
||||
}
|
||||
patterns := make([]*hugio.HasBytesPattern, len(fs.patterns))
|
||||
for i, p := range fs.patterns {
|
||||
patterns[i] = &hugio.HasBytesPattern{Pattern: p}
|
||||
}
|
||||
|
||||
return &hasBytesFile{
|
||||
File: f,
|
||||
hbw: &hugio.HasBytesWriter{
|
||||
Pattern: fs.pattern,
|
||||
Patterns: patterns,
|
||||
},
|
||||
hasBytesCallback: fs.hasBytesCallback,
|
||||
}
|
||||
@@ -74,7 +79,7 @@ func (fs *hasBytesFs) Name() string {
|
||||
}
|
||||
|
||||
type hasBytesFile struct {
|
||||
hasBytesCallback func(name string, match bool)
|
||||
hasBytesCallback func(name string, match []byte)
|
||||
hbw *hugio.HasBytesWriter
|
||||
afero.File
|
||||
}
|
||||
@@ -88,6 +93,10 @@ func (h *hasBytesFile) Write(p []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
func (h *hasBytesFile) Close() error {
|
||||
h.hasBytesCallback(h.Name(), h.hbw.Match)
|
||||
for _, p := range h.hbw.Patterns {
|
||||
if p.Match {
|
||||
h.hasBytesCallback(h.Name(), p.Pattern)
|
||||
}
|
||||
}
|
||||
return h.File.Close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user