symlink_unix.go 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/protocol"
  11. "github.com/syncthing/syncthing/internal/osutil"
  12. )
  13. var (
  14. Supported = true
  15. )
  16. func Read(path string) (string, uint32, error) {
  17. var mode uint32
  18. stat, err := os.Stat(path)
  19. if err != nil {
  20. mode = protocol.FlagSymlinkMissingTarget
  21. } else if stat.IsDir() {
  22. mode = protocol.FlagDirectory
  23. }
  24. path, err = os.Readlink(path)
  25. return osutil.NormalizedFilename(path), mode, err
  26. }
  27. func Create(source, target string, flags uint32) error {
  28. return os.Symlink(osutil.NativeFilename(target), source)
  29. }
  30. func ChangeType(path string, flags uint32) error {
  31. return nil
  32. }