From d80318415d27dea616156c33e91c8f81d8cc5c57 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 2 Sep 2010 11:18:57 -0400 Subject: [PATCH] Implement file removal in the backend. --- src/paths.go | 10 +++++++++- src/server.go | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/paths.go b/src/paths.go index a2677f0..1229b0e 100644 --- a/src/paths.go +++ b/src/paths.go @@ -39,7 +39,7 @@ func checkInJail(the_path string) bool { func List(the_path string) (files vector.StringVector, err os.Error) { full_path := canonicalizePath(the_path) if !checkInJail(full_path) { - return nil, os.NewError("path outside of jail") + return nil, os.NewError("Path outside of jail") } fd, file_error := os.Open(full_path, os.O_RDONLY, 0) @@ -61,3 +61,11 @@ func List(the_path string) (files vector.StringVector, err os.Error) { } return files, nil } + +func Remove(the_path string) os.Error { + full_path := canonicalizePath(the_path) + if !checkInJail(full_path) { + return os.NewError("Path outside of jail") + } + return os.RemoveAll(full_path) +} diff --git a/src/server.go b/src/server.go index 1533f08..aceb130 100644 --- a/src/server.go +++ b/src/server.go @@ -46,6 +46,16 @@ func serviceHandler(connection *http.Conn, request *http.Request) { } else { okResponse(connection, files) } + case "remove": + err := paths.Remove(request.FormValue("path")) + if err != nil { + errorResponse(connection, err.String()) + } else { + response := map[string] int { + "error" : 0, + } + okResponse(connection, response) + } default: errorResponse(connection, "Unhandled action") } @@ -54,8 +64,8 @@ func serviceHandler(connection *http.Conn, request *http.Request) { func errorResponse(connection *http.Conn, message string) { message = strings.Replace(message, paths.JailRoot, "/", -1) response := map[string] string { - "error": "-1", - "message": message, + "error" : "-1", + "message" : message, } json_data, err := json.Marshal(response) -- 2.22.5