spec_other.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //go:build !linux
  2. // +build !linux
  3. /*
  4. Copyright © 2022 The CDI Authors
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. package cdi
  16. import (
  17. "os"
  18. "path/filepath"
  19. )
  20. // Rename src to dst, both relative to the directory dir. If dst already exists
  21. // refuse renaming with an error unless overwrite is explicitly asked for.
  22. func renameIn(dir, src, dst string, overwrite bool) error {
  23. src = filepath.Join(dir, src)
  24. dst = filepath.Join(dir, dst)
  25. _, err := os.Stat(dst)
  26. if err == nil && !overwrite {
  27. return os.ErrExist
  28. }
  29. return os.Rename(src, dst)
  30. }