2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
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.
21 var gConfig *config.Configuration
23 func SetConfig(aConfig *config.Configuration) {
25 gJailRoot = aConfig.JailRoot
28 func canonicalizePath(raw_path string) string {
29 raw_path = path.Join(gJailRoot, raw_path)
30 return path.Clean(raw_path)
33 func checkInJail(the_path string) bool {
34 if len(the_path) < len(gJailRoot) {
37 if the_path[0:len(gJailRoot)] != gJailRoot {
40 if strings.Index(the_path, "../") != -1 {
46 func List(the_path string) (files vector.StringVector, err os.Error) {
47 full_path := canonicalizePath(the_path)
48 if !checkInJail(full_path) {
49 return nil, os.NewError("Path outside of jail")
52 fd, file_error := os.Open(full_path, os.O_RDONLY, 0)
53 if file_error != nil {
54 return nil, file_error
57 fileinfos, read_err := fd.Readdir(-1)
62 for _, info := range fileinfos {
64 if info.IsDirectory() {
67 if !gConfig.IncludeDotfiles && name[0] == '.' {
75 func Remove(the_path string) os.Error {
76 full_path := canonicalizePath(the_path)
77 if !checkInJail(full_path) {
78 return os.NewError("Path outside of jail")
80 return os.RemoveAll(full_path)
83 func Move(source string, target string) os.Error {
84 source = canonicalizePath(source)
85 target = canonicalizePath(target)
86 if !checkInJail(source) {
87 return os.NewError("Source outside of jail")
89 if !checkInJail(target) {
90 return os.NewError("Target outside of jail")
92 return os.Rename(source, target)