Start work on rewriting the TV renamer in Go
[armadillo.git] / src / tv_rename.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2011, Robert Sesek <http://www.bluestatic.org>
4 //
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.
8 //
9
10 package tv_rename
11
12 import (
13 "fmt"
14 "os"
15 "./paths"
16 )
17
18 // Takes a full file path and renames the last path component as if it were a
19 // TV episode. This performs the actual rename as well.
20 func RenameEpisode(inPath string) (*string, os.Error) {
21 // Make sure a path was given.
22 if len(inPath) < 1 {
23 return nil, os.NewError("Invalid path")
24 }
25 // Check that it's inside the jail.
26 var path *string = paths.Verify(inPath)
27 if path == nil {
28 return nil, os.NewError("Path is invalid or outside of jail")
29 }
30 // Make sure that the file exists.
31 fileInfo, err := os.Stat(*path)
32 if err != nil {
33 return nil, err
34 }
35 return path, nil
36 }