Add GPL file headers
[armadillo.git] / src / paths.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 package paths
11
12 import (
13 "container/vector"
14 "os"
15 "path"
16 )
17
18 var JailRoot string;
19
20 func canonicalizePath(raw_path string) string {
21 raw_path = path.Join(JailRoot, raw_path)
22 return path.Clean(raw_path)
23 }
24
25 func checkInJail(path string) bool {
26 return true
27 }
28
29 func List(the_path string) (files vector.StringVector, err os.Error) {
30 full_path := canonicalizePath(the_path)
31 if !checkInJail(full_path) {
32 return nil, os.NewError("path outside of jail")
33 }
34
35 fd, file_error := os.Open(full_path, os.O_RDONLY, 0)
36 if file_error != nil {
37 return nil, file_error
38 }
39
40 fileinfos, read_err := fd.Readdir(-1)
41 if read_err != nil {
42 return nil, read_err
43 }
44
45 for _, info := range fileinfos {
46 name := info.Name
47 if info.IsDirectory() {
48 name += "/"
49 }
50 files.Push(name)
51 }
52 return files, nil
53 }