remove requestpath's abspath member, modify function names

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
master
kim (grufwub) 4 years ago
parent 442404e592
commit 804df8bb26

@ -232,7 +232,7 @@ func readGophermap(requestPath *RequestPath) ([]GophermapSection, *GophorError)
case TypeEndBeginList:
/* Create GophermapDirListing object then break out at end of loop */
dirPath := requestPath.NewTrimmedPathFromCurrent(GophermapFileStr)
dirPath := requestPath.NewTrimPathFromCurrent(GophermapFileStr)
dirListing = NewGophermapDirListing(dirPath)
return false

@ -75,7 +75,7 @@ func (fs *FileSystem) HandleRequest(requestPath *RequestPath, host *ConnHost) ([
/* Directory */
case FileTypeDir:
/* Check Gophermap exists */
gophermapPath := requestPath.NewJoinedPathFromCurrent(GophermapFileStr)
gophermapPath := requestPath.NewJoinPathFromCurrent(GophermapFileStr)
_, err := os.Stat(gophermapPath.AbsolutePath())
var output []byte

@ -125,12 +125,12 @@ func _listDir(request *FileSystemRequest, hidden map[string]bool) ([]byte, *Goph
switch {
case file.Mode() & os.ModeDir != 0:
/* Directory -- create directory listing */
itemPath := request.Path.SelectorPathJoin(file.Name())
itemPath := request.Path.JoinSelectorPath(file.Name())
*dirContents = append(*dirContents, buildLine(TypeDirectory, file.Name(), itemPath, request.Host.Name, request.Host.Port)...)
case file.Mode() & os.ModeType == 0:
/* Regular file -- find item type and creating listing */
itemPath := request.Path.SelectorPathJoin(file.Name())
itemPath := request.Path.JoinSelectorPath(file.Name())
itemType := getItemType(itemPath)
*dirContents = append(*dirContents, buildLine(itemType, file.Name(), itemPath, request.Host.Name, request.Host.Port)...)
@ -153,12 +153,12 @@ func _listDirRegexMatch(request *FileSystemRequest, hidden map[string]bool) ([]b
switch {
case file.Mode() & os.ModeDir != 0:
/* Directory -- create directory listing */
itemPath := request.Path.SelectorPathJoin(file.Name())
itemPath := request.Path.JoinSelectorPath(file.Name())
*dirContents = append(*dirContents, buildLine(TypeDirectory, file.Name(), itemPath, request.Host.Name, request.Host.Port)...)
case file.Mode() & os.ModeType == 0:
/* Regular file -- find item type and creating listing */
itemPath := request.Path.SelectorPathJoin(file.Name())
itemPath := request.Path.JoinSelectorPath(file.Name())
itemType := getItemType(itemPath)
*dirContents = append(*dirContents, buildLine(itemType, file.Name(), itemPath, request.Host.Name, request.Host.Port)...)

@ -21,7 +21,6 @@ type FileSystemRequest struct {
type RequestPath struct {
Root string
Path string
AbsPath string
}
func NewRequestPath(root, request string) *RequestPath {
@ -38,7 +37,7 @@ func NewRequestPath(root, request string) *RequestPath {
}
}
return &RequestPath{ root, requestPath, "" }
return &RequestPath{ root, requestPath }
}
func (rp *RequestPath) SelectorPath() string {
@ -50,17 +49,14 @@ func (rp *RequestPath) SelectorPath() string {
}
func (rp *RequestPath) AbsolutePath() string {
if rp.AbsPath == "" {
rp.AbsPath = path.Join(rp.Root, rp.Path)
}
return rp.AbsPath
return path.Join(rp.Root, rp.Path)
}
func (rp *RequestPath) RelativePath() string {
return rp.Path
}
func (rp *RequestPath) SelectorPathJoin(extPath string) string {
func (rp *RequestPath) JoinSelectorPath(extPath string) string {
if rp.Path == "." {
return path.Join("/", extPath)
} else {
@ -92,13 +88,13 @@ func (rp *RequestPath) TrimAbsoluteSuffix(suffix string) string {
return strings.TrimSuffix(rp.AbsolutePath(), suffix)
}
func (rp *RequestPath) NewJoinedPathFromCurrent(extPath string) *RequestPath {
func (rp *RequestPath) NewJoinPathFromCurrent(extPath string) *RequestPath {
/* DANGER THIS DOES NOT CHECK FOR BACK-DIR TRAVERSALS */
return &RequestPath{ rp.Root, rp.JoinRelativePath(extPath), "" }
return &RequestPath{ rp.Root, rp.JoinRelativePath(extPath) }
}
func (rp *RequestPath) NewTrimmedPathFromCurrent(trimSuffix string) *RequestPath {
return &RequestPath{ rp.Root, rp.TrimRelativeSuffix(trimSuffix), "" }
func (rp *RequestPath) NewTrimPathFromCurrent(trimSuffix string) *RequestPath {
return &RequestPath{ rp.Root, rp.TrimRelativeSuffix(trimSuffix) }
}
func (rp *RequestPath) NewPathAtRoot(extPath string) *RequestPath {

Loading…
Cancel
Save