debug_symlink_unix.go 1015 B

123456789101112131415161718192021222324252627282930313233
  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. //go:build !windows
  7. // +build !windows
  8. package fs
  9. import (
  10. "os"
  11. "path/filepath"
  12. )
  13. // DebugSymlinkForTestsOnly is not and should not be used in Syncthing code,
  14. // hence the cumbersome name to make it obvious if this ever leaks. Its
  15. // reason for existence is the Windows version, which allows creating
  16. // symlinks when non-elevated.
  17. func DebugSymlinkForTestsOnly(oldFs, newFs Filesystem, oldname, newname string) error {
  18. if fs, ok := unwrapFilesystem(newFs, filesystemWrapperTypeCase); ok {
  19. caseFs := fs.(*caseFilesystem)
  20. if err := caseFs.checkCase(newname); err != nil {
  21. return err
  22. }
  23. caseFs.dropCache()
  24. }
  25. if err := os.Symlink(filepath.Join(oldFs.URI(), oldname), filepath.Join(newFs.URI(), newname)); err != nil {
  26. return err
  27. }
  28. return nil
  29. }