fix: do not read whole file on listings
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: c630ed523a9f599c3dd1eda5930baa020d0b9911 [formerly f89f524d2979e43d6c2fd99903552bfe89addbc1] [formerly ba05ce7e5c730a04681910d87378dcdf3acc809b [formerly 28b326ab1d
]]
Former-commit-id: cc4832f376eb2e5d5c99dfdac9b1966448b4e48f [formerly f254f221fa44f016a8f22cb3414580bb3a57750b]
Former-commit-id: 66c66d82ade69e62d32e05f8350166b2cdc3bb12
pull/726/head
parent
1db210a24f
commit
3890a9a416
|
@ -76,7 +76,7 @@ func NewFileInfo(opts FileOptions) (*FileInfo, error) {
|
|||
return file, file.readListing(opts.Checker)
|
||||
}
|
||||
|
||||
err = file.detectType(opts.Modify)
|
||||
err = file.detectType(opts.Modify, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func (i *FileInfo) Checksum(algo string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (i *FileInfo) detectType(modify bool) error {
|
||||
func (i *FileInfo) detectType(modify, saveContent bool) error {
|
||||
reader, err := i.Fs.Open(i.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -160,17 +160,20 @@ func (i *FileInfo) detectType(modify bool) error {
|
|||
return nil
|
||||
default:
|
||||
i.Type = "text"
|
||||
afs := &afero.Afero{Fs: i.Fs}
|
||||
content, err := afs.ReadFile(i.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !modify {
|
||||
i.Type = "textImmutable"
|
||||
}
|
||||
|
||||
i.Content = string(content)
|
||||
if saveContent {
|
||||
afs := &afero.Afero{Fs: i.Fs}
|
||||
content, err := afs.ReadFile(i.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Content = string(content)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -238,7 +241,7 @@ func (i *FileInfo) readListing(checker rules.Checker) error {
|
|||
} else {
|
||||
listing.NumFiles++
|
||||
|
||||
err := file.detectType(true)
|
||||
err := file.detectType(true, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue