#!/usr/bin/env python2.5
#
# Armadillo File Manager
-# Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
+# Copyright (c) 2010-2011, Robert Sesek <http://www.bluestatic.org>
#
# 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
SOURCES = [
'config.go',
'paths.go',
+ 'tv_rename.go',
'server.go',
'main.go'
]
//
// Armadillo File Manager
-// Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
+// Copyright (c) 2010-2011, Robert Sesek <http://www.bluestatic.org>
//
// 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
return true
}
+// Verifies that the path is in the jail and returns the cleaned-up path. Will
+// return nil on error.
+func Verify(thePath string) *string {
+ fullPath := canonicalizePath(thePath)
+ if !checkInJail(fullPath) {
+ return nil
+ }
+ return &fullPath
+}
+
func List(the_path string) (files vector.StringVector, err os.Error) {
full_path := canonicalizePath(the_path)
if !checkInJail(full_path) {
"strings"
"./config"
"./paths"
+ "./tv_rename"
)
var dir, file = path.Split(path.Clean(os.Getenv("_")))
}
okResponse(response, data)
}
+ case "tv_rename":
+ newPath, err := tv_rename.RenameEpisode(request.FormValue("path"))
+ if err != nil {
+ errorResponse(response, err.String())
+ } else {
+ data := map[string] interface{} {
+ "path" : *newPath,
+ "error" : 0,
+ }
+ okResponse(response, data)
+ }
default:
+ fmt.Printf("Invalid action: '%s'\n", request.FormValue("action"))
errorResponse(response, "Unhandled action")
}
}
--- /dev/null
+//
+// Armadillo File Manager
+// Copyright (c) 2011, Robert Sesek <http://www.bluestatic.org>
+//
+// 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.
+//
+
+package tv_rename
+
+import (
+ "fmt"
+ "os"
+ "./paths"
+)
+
+// Takes a full file path and renames the last path component as if it were a
+// TV episode. This performs the actual rename as well.
+func RenameEpisode(inPath string) (*string, os.Error) {
+ // Make sure a path was given.
+ if len(inPath) < 1 {
+ return nil, os.NewError("Invalid path")
+ }
+ // Check that it's inside the jail.
+ var path *string = paths.Verify(inPath)
+ if path == nil {
+ return nil, os.NewError("Path is invalid or outside of jail")
+ }
+ // Make sure that the file exists.
+ fileInfo, err := os.Stat(*path)
+ if err != nil {
+ return nil, err
+ }
+ return path, nil
+}