|
|
|
@ -106,14 +106,11 @@ func (fs *FileSystemObject) ReadFile(fd *os.File) ([]byte, Error) {
|
|
|
|
|
|
|
|
|
|
// Read buffer
|
|
|
|
|
buf := make([]byte, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Declare variables
|
|
|
|
|
var count int
|
|
|
|
|
var err error
|
|
|
|
|
rd := bufio.NewReaderSize(fd, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Read through file until null bytes / error
|
|
|
|
|
for {
|
|
|
|
|
count, err = fd.Read(buf)
|
|
|
|
|
count, err := rd.Read(buf)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err == io.EOF {
|
|
|
|
|
break
|
|
|
|
@ -134,23 +131,18 @@ func (fs *FileSystemObject) ReadFile(fd *os.File) ([]byte, Error) {
|
|
|
|
|
// ScanFile scans a supplied file at file descriptor, using iterator function
|
|
|
|
|
func (fs *FileSystemObject) ScanFile(fd *os.File, iterator func(string) bool) Error {
|
|
|
|
|
// Buffered reader
|
|
|
|
|
rdr := bufio.NewReaderSize(fd, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Declare variables
|
|
|
|
|
var b, line []byte
|
|
|
|
|
var err error
|
|
|
|
|
var isPrefix, done bool
|
|
|
|
|
rd := bufio.NewReaderSize(fd, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Iterate through file!
|
|
|
|
|
for {
|
|
|
|
|
// Line buffer
|
|
|
|
|
b = make([]byte, 0)
|
|
|
|
|
b := make([]byte, 0)
|
|
|
|
|
|
|
|
|
|
// Read until line-end, or file end!
|
|
|
|
|
done = false
|
|
|
|
|
done := false
|
|
|
|
|
for {
|
|
|
|
|
// Read a line
|
|
|
|
|
line, isPrefix, err = rdr.ReadLine()
|
|
|
|
|
line, isPrefix, err := rd.ReadLine()
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err == io.EOF {
|
|
|
|
|
done = true
|
|
|
|
@ -190,13 +182,10 @@ func (fs *FileSystemObject) ScanDirectory(fd *os.File, p *Path, iterator func(os
|
|
|
|
|
// Sort by name
|
|
|
|
|
sort.Sort(byName(dirList))
|
|
|
|
|
|
|
|
|
|
// Declare variables
|
|
|
|
|
var fp *Path
|
|
|
|
|
|
|
|
|
|
// Walk through the directory list using supplied iterator function
|
|
|
|
|
for _, info := range dirList {
|
|
|
|
|
// Make new Path object
|
|
|
|
|
fp = p.JoinPath(info.Name())
|
|
|
|
|
fp := p.JoinPath(info.Name())
|
|
|
|
|
|
|
|
|
|
// Skip restricted files
|
|
|
|
|
if IsRestrictedPath(fp) || WithinCGIDir(fp) {
|
|
|
|
@ -296,7 +285,7 @@ func (fs *FileSystemObject) HandleClient(client *Client, request *Request, newFi
|
|
|
|
|
func (fs *FileSystemObject) FetchFile(client *Client, fd *os.File, stat os.FileInfo, p *Path, newFileContents func(*Path) FileContents) Error {
|
|
|
|
|
// If file too big, write direct to client
|
|
|
|
|
if stat.Size() > fileSizeMax {
|
|
|
|
|
return client.Conn().WriteFrom(fd)
|
|
|
|
|
return client.Conn().ReadFrom(fd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get cache read lock, defer unlock
|
|
|
|
|