basicfs_symlink_unix.go 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2016 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 http://mozilla.org/MPL/2.0/.
  6. // +build !windows
  7. package fs
  8. import "os"
  9. var symlinksSupported = true
  10. func DisableSymlinks() {
  11. symlinksSupported = false
  12. }
  13. func (BasicFilesystem) SymlinksSupported() bool {
  14. return symlinksSupported
  15. }
  16. func (BasicFilesystem) CreateSymlink(name, target string, _ LinkTargetType) error {
  17. return os.Symlink(target, name)
  18. }
  19. func (BasicFilesystem) ChangeSymlinkType(_ string, _ LinkTargetType) error {
  20. return nil
  21. }
  22. func (BasicFilesystem) ReadSymlink(path string) (string, LinkTargetType, error) {
  23. tt := LinkTargetUnknown
  24. if stat, err := os.Stat(path); err == nil {
  25. if stat.IsDir() {
  26. tt = LinkTargetDirectory
  27. } else {
  28. tt = LinkTargetFile
  29. }
  30. }
  31. path, err := os.Readlink(path)
  32. return path, tt, err
  33. }