|
|
|
@ -65,7 +65,7 @@ func (fs *FileSystemObject) checkCacheFreshness() {
|
|
|
|
|
// Check file still exists on disk
|
|
|
|
|
stat, err := os.Stat(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
SystemLog.Error("Failed to stat file in cache: %s\n", path)
|
|
|
|
|
SystemLog.Error(cacheFileStatErrStr, path)
|
|
|
|
|
fs.cache.Remove(path)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -107,9 +107,13 @@ func (fs *FileSystemObject) ReadFile(fd *os.File) ([]byte, Error) {
|
|
|
|
|
// Read buffer
|
|
|
|
|
buf := make([]byte, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Declare variables
|
|
|
|
|
var count int
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
// Read through file until null bytes / error
|
|
|
|
|
for {
|
|
|
|
|
count, err := fd.Read(buf)
|
|
|
|
|
count, err = fd.Read(buf)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err == io.EOF {
|
|
|
|
|
break
|
|
|
|
@ -132,17 +136,24 @@ func (fs *FileSystemObject) ScanFile(fd *os.File, iterator func(string) bool) Er
|
|
|
|
|
// Buffered reader
|
|
|
|
|
rdr := bufio.NewReaderSize(fd, fileReadBufSize)
|
|
|
|
|
|
|
|
|
|
// Declare variables
|
|
|
|
|
var b, line []byte
|
|
|
|
|
var err error
|
|
|
|
|
var isPrefix, done bool
|
|
|
|
|
|
|
|
|
|
// Iterate through file!
|
|
|
|
|
for {
|
|
|
|
|
// Line buffer
|
|
|
|
|
b := make([]byte, 0)
|
|
|
|
|
b = make([]byte, 0)
|
|
|
|
|
|
|
|
|
|
// Read until line-end, or file end!
|
|
|
|
|
done = false
|
|
|
|
|
for {
|
|
|
|
|
// Read a line
|
|
|
|
|
line, isPrefix, err := rdr.ReadLine()
|
|
|
|
|
line, isPrefix, err = rdr.ReadLine()
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err == io.EOF {
|
|
|
|
|
done = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
return WrapError(FileReadErr, err)
|
|
|
|
@ -158,9 +169,12 @@ func (fs *FileSystemObject) ScanFile(fd *os.File, iterator func(string) bool) Er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run scan iterator on this line, break-out if requested
|
|
|
|
|
if !iterator(string(b)) {
|
|
|
|
|
if !iterator(string(b)) || done {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty the slice!
|
|
|
|
|
b = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
@ -176,10 +190,13 @@ 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) {
|
|
|
|
@ -337,7 +354,7 @@ func (fs *FileSystemObject) FetchFile(client *Client, fd *os.File, stat os.FileI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Defer file unlock, write to client
|
|
|
|
|
// Defer file read unlock, write to client
|
|
|
|
|
defer f.RUnlock()
|
|
|
|
|
return f.WriteToClient(client, p)
|
|
|
|
|
}
|
|
|
|
|