From 1964ef0dd78430444faf1439ddb10ab16e25da33 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 20 Sep 2011 08:50:01 -0400 Subject: [PATCH] Add the backend for making new directories --- src/paths.go | 15 +++++++++++++++ src/server.go | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/paths.go b/src/paths.go index 522b3f6..42fbb0c 100644 --- a/src/paths.go +++ b/src/paths.go @@ -95,3 +95,18 @@ func Move(source string, target string) os.Error { } return os.Rename(source, target) } + +func MakeDir(target string) os.Error { + target = canonicalizePath(target) + if !checkInJail(target) { + return os.NewError("Path outside of jail") + } + + dir, _ := path.Split(target) + isValid, _ := IsValid(dir) + if !isValid { + return os.NewError("Containing directory not valid") + } + + return os.Mkdir(target, 0644) +} diff --git a/src/server.go b/src/server.go index cde9c33..d050b42 100644 --- a/src/server.go +++ b/src/server.go @@ -1,7 +1,7 @@ // // Armadillo File Manager -// Copyright (c) 2010, Robert Sesek -// +// Copyright (c) 2010-2011, Robert Sesek +// // This program is free software: you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation, either version 3 of the License, or any later version. @@ -73,6 +73,18 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { } okResponse(response, data) } + case "mkdir": + path := request.FormValue("path") + err := paths.MakeDir(path) + if err != nil { + errorResponse(response, err.String()) + } else { + data := map[string]interface{}{ + "path": path, + "error": 0, + } + okResponse(response, data) + } case "tv_rename": newPath, err := tv_rename.RenameEpisode(request.FormValue("path")) if err != nil { -- 2.43.5