blob: ad59aae3dc8756a61e7232efc3ada5bd99adaa02 [file] [log] [blame]
// Package impl implements the LogFile interface from
// veyron2/services/mgmt/logreader, which can be used to allow remote access to
// log files, and the Globbable interface from veyron2/services/mounttable to
// find the files in a logs directory.
package impl
import (
"path"
"strings"
"veyron2/services/mgmt/logreader/types"
"veyron2/verror"
)
var (
errCanceled = verror.Abortedf("operation canceled")
errNotFound = verror.NotFoundf("log file not found")
errEOF = verror.Make(types.EOF, "EOF")
errOperationFailed = verror.Internalf("operation failed")
)
// translateNameToFilename returns the file name that corresponds to the object
// name.
func translateNameToFilename(root, name string) (string, error) {
p := path.Join(root, name)
// Make sure we're not asked to read a file outside of the root
// directory. This could happen if suffix contains "../", which get
// collapsed by path.Join().
if !strings.HasPrefix(p, root) {
return "", errOperationFailed
}
return p, nil
}