osutil.go 557 B

12345678910111213141516171819202122
  1. // Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
  2. // Use of this source code is governed by an MIT-style license that can be
  3. // found in the LICENSE file.
  4. package osutil
  5. import (
  6. "os"
  7. "runtime"
  8. )
  9. func Rename(from, to string) error {
  10. if runtime.GOOS == "windows" {
  11. os.Chmod(to, 0666) // Make sure the file is user writeable
  12. err := os.Remove(to)
  13. if err != nil && !os.IsNotExist(err) {
  14. return err
  15. }
  16. }
  17. defer os.Remove(from) // Don't leave a dangling temp file in case of rename error
  18. return os.Rename(from, to)
  19. }