symlink_unix.go 783 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2014 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 symlinks
  8. import (
  9. "os"
  10. "github.com/syncthing/syncthing/lib/osutil"
  11. )
  12. var (
  13. Supported = true
  14. )
  15. func Read(path string) (string, TargetType, error) {
  16. tt := TargetUnknown
  17. if stat, err := os.Stat(path); err == nil {
  18. if stat.IsDir() {
  19. tt = TargetDirectory
  20. } else {
  21. tt = TargetFile
  22. }
  23. }
  24. path, err := os.Readlink(path)
  25. return osutil.NormalizedFilename(path), tt, err
  26. }
  27. func Create(source, target string, tt TargetType) error {
  28. return os.Symlink(osutil.NativeFilename(target), source)
  29. }