1
0

debug_symlink_unix.go 995 B

1234567891011121314151617181920212223242526272829303132
  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 fs, ok := unwrapFilesystem(newFs, filesystemWrapperTypeCase); ok {
  18. caseFs := fs.(*caseFilesystem)
  19. if err := caseFs.checkCase(newname); err != nil {
  20. return err
  21. }
  22. caseFs.dropCache()
  23. }
  24. if err := os.Symlink(filepath.Join(oldFs.URI(), oldname), filepath.Join(newFs.URI(), newname)); err != nil {
  25. return err
  26. }
  27. return nil
  28. }