]>
src.bluestatic.org Git - armadillo.git/blob - src/paths.go
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 func canonicalizePath(raw_path
string) string {
22 raw_path
= path
.Join(JailRoot
, raw_path
)
23 return path
.Clean(raw_path
)
26 func checkInJail(the_path
string) bool {
27 if len(the_path
) < len(JailRoot
) {
30 if the_path
[0:len(JailRoot
)] != JailRoot
{
33 if strings
.Index(the_path
, "../") != -1 {
39 func List(the_path
string) (files vector
.StringVector
, err os
.Error
) {
40 full_path
:= canonicalizePath(the_path
)
41 if !checkInJail(full_path
) {
42 return nil, os
.NewError("Path outside of jail")
45 fd
, file_error
:= os
.Open(full_path
, os
.O_RDONLY
, 0)
46 if file_error
!= nil {
47 return nil, file_error
50 fileinfos
, read_err
:= fd
.Readdir(-1)
55 for _
, info
:= range fileinfos
{
57 if info
.IsDirectory() {
65 func Remove(the_path
string) os
.Error
{
66 full_path
:= canonicalizePath(the_path
)
67 if !checkInJail(full_path
) {
68 return os
.NewError("Path outside of jail")
70 return os
.RemoveAll(full_path
)
73 func Move(source
string, target
string) os
.Error
{
74 source
= canonicalizePath(source
)
75 target
= canonicalizePath(target
)
76 if !checkInJail(source
) {
77 return os
.NewError("Source outside of jail")
79 if !checkInJail(target
) {
80 return os
.NewError("Target outside of jail")
82 return os
.Rename(source
, target
)