2016-03-16 19:59:34 +00:00
|
|
|
package mtree
|
|
|
|
|
2016-03-18 20:31:12 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
|
2016-03-16 19:59:34 +00:00
|
|
|
type Result struct {
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:31:12 +00:00
|
|
|
var ErrNotAllClear = fmt.Errorf("some keyword check failed validation")
|
|
|
|
|
2016-03-16 19:59:34 +00:00
|
|
|
func Check(root string, dh *DirectoryHierarchy) (*Result, error) {
|
2016-03-18 20:31:12 +00:00
|
|
|
creator := dhCreator{DH: dh}
|
|
|
|
curDir, err := os.Getwd()
|
|
|
|
if err == nil {
|
|
|
|
defer os.Chdir(curDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Chdir(root); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sort.Sort(byPos(creator.DH.Entries))
|
|
|
|
|
|
|
|
for _, e := range creator.DH.Entries {
|
|
|
|
switch e.Type {
|
|
|
|
case SpecialType:
|
|
|
|
if e.Name == "/set" {
|
|
|
|
creator.curSet = &e
|
|
|
|
} else if e.Name == "/unset" {
|
|
|
|
creator.curSet = nil
|
|
|
|
}
|
|
|
|
case DotDotType:
|
|
|
|
// TODO step
|
|
|
|
case RelativeType:
|
|
|
|
// TODO determine path, and check keywords
|
|
|
|
// or maybe to Chdir when type=dir?
|
|
|
|
case FullType:
|
|
|
|
info, err := os.Lstat(filepath.Join(root, e.Name))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// TODO check against keywords present
|
|
|
|
_ = info
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 19:59:34 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|