From c9dba4936625c585c3b0a1bccb7d1b941889271a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 4 Dec 2009 11:46:56 -0800 Subject: Add os.Rename. R=rsc http://codereview.appspot.com/166058 --- src/pkg/os/file.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/pkg/os/file.go') diff --git a/src/pkg/os/file.go b/src/pkg/os/file.go index dc722055a..03c6d5701 100644 --- a/src/pkg/os/file.go +++ b/src/pkg/os/file.go @@ -370,7 +370,7 @@ func Remove(name string) Error { return &PathError{"remove", name, Errno(e)}; } -// LinkError records an error during a link or symlink +// LinkError records an error during a link or symlink or rename // system call and the paths that caused it. type LinkError struct { Op string; @@ -418,6 +418,15 @@ func Readlink(name string) (string, Error) { return "", nil; } +// Rename renames a file. +func Rename(oldname, newname string) Error { + e := syscall.Rename(oldname, newname); + if e != 0 { + return &LinkError{"rename", oldname, newname, Errno(e)} + } + return nil; +} + // Chmod changes the mode of the named file to mode. // If the file is a symbolic link, it changes the uid and gid of the link's target. func Chmod(name string, mode int) Error { -- cgit v1.2.3