diff --git a/server/server/errors.go b/server/server/errors.go index 208173d..b487963 100644 --- a/server/server/errors.go +++ b/server/server/errors.go @@ -39,10 +39,16 @@ var ( ErrStackCast = StackError{"StackCastError", errors.New("stack can't be casted to selected type")} ) +type PathError struct { + Err error +} + +func (e PathError) Error() string { return "Error: " + e.Err.Error() } + // PathErrors var ( - ErrInvalidDirectoryName = errors.New("names should not contain / character") - ErrNotADirectory = errors.New("file name is not a valid directory") - ErrAlreadyAtBaseDirectory = errors.New("can't go past beyond root directory") - ErrSlashNotAllowed = errors.New("slash is not allowed in file names") + ErrInvalidDirectoryName = PathError{errors.New("names should not contain / character")} + ErrNotADirectory = PathError{errors.New("file name is not a valid directory")} + ErrAlreadyAtBaseDirectory = PathError{errors.New("can't go past beyond root directory")} + ErrSlashNotAllowed = PathError{errors.New("slash is not allowed in file names")} ) diff --git a/server/server/path.go b/server/server/path.go index fafa1c5..fb06512 100644 --- a/server/server/path.go +++ b/server/server/path.go @@ -39,16 +39,13 @@ func MakePathFromStringStack(stack *StringStack) string { // ChangeDirectory changes the current working directory with respect to BasePath func ChangeDirectory(stack *StringStack, directory string) error { - if containsSlash(directory) == true { - return ErrInvalidDirectoryName - } stack.Push(directory) path := MakePathFromStringStack(stack) fileInfo, err := os.Stat(path) if err != nil { stack.Pop() - return err + return PathError{err} } if fileInfo.IsDir() == false { @@ -64,7 +61,7 @@ func ChangeDirectory(stack *StringStack, directory string) error { return nil } stack.Pop() - return os.ErrPermission + return PathError{err} } // ChangeDirectoryToPrevious changes the current working directory to the previous one, diff --git a/server/server/path_test.go b/server/server/path_test.go index 78cc0f1..deb6258 100644 --- a/server/server/path_test.go +++ b/server/server/path_test.go @@ -84,14 +84,6 @@ func TestChangeDirectory_InvalidDirectoryIsNotInStack(t *testing.T) { } -func TestChangeDirectory_InvalidDirectoryName(t *testing.T) { - st := MakeStringStack(1) - err := ChangeDirectory(st, "some/not/cool/directory/") - if err != ErrInvalidDirectoryName { - t.Error("TestChangeDirectory: Changed directory to something containing the '/' character!") - } -} - func TestChangeDirectoryToPrevious_StackIsEmpty(t *testing.T) { st := MakeStringStack(1) err := ChangeDirectoryToPrevious(st)