debug_symlink_unix.go 957 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2017 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. // +build !windows
  7. package fs
  8. import (
  9. "os"
  10. "path/filepath"
  11. )
  12. // DebugSymlinkForTestsOnly is not and should not be used in Syncthing code,
  13. // hence the cumbersome name to make it obvious if this ever leaks. Its
  14. // reason for existence is the Windows version, which allows creating
  15. // symlinks when non-elevated.
  16. func DebugSymlinkForTestsOnly(oldFs, newFs Filesystem, oldname, newname string) error {
  17. if caseFs, ok := unwrapFilesystem(newFs).(*caseFilesystem); ok {
  18. if err := caseFs.checkCase(newname); err != nil {
  19. return err
  20. }
  21. caseFs.dropCache()
  22. }
  23. if err := os.Symlink(filepath.Join(oldFs.URI(), oldname), filepath.Join(newFs.URI(), newname)); err != nil {
  24. return err
  25. }
  26. return nil
  27. }