Add path listing service.
[armadillo.git] / src / paths.go
1 package paths
2
3 import (
4 "container/vector"
5 "os"
6 "path"
7 )
8
9 const kJailRoot = "/Users/rsesek/Downloads"
10
11 func canonicalizePath(raw_path string) string {
12 raw_path = path.Join(kJailRoot, raw_path)
13 return path.Clean(raw_path)
14 }
15
16 func checkInJail(path string) bool {
17 return true
18 }
19
20 func List(the_path string) (files vector.StringVector, err os.Error) {
21 full_path := canonicalizePath(the_path)
22 if !checkInJail(full_path) {
23 return nil, os.NewError("path outside of jail")
24 }
25
26 fd, file_error := os.Open(full_path, os.O_RDONLY, 0)
27 if file_error != nil {
28 return nil, file_error
29 }
30
31 fileinfos, read_err := fd.Readdir(-1)
32 if read_err != nil {
33 return nil, read_err
34 }
35
36 for _, info := range fileinfos {
37 files.Push(info.Name)
38 }
39 return files, nil
40 }