symlink_unix.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. // +build !windows
  16. package symlinks
  17. import (
  18. "os"
  19. "github.com/syncthing/syncthing/internal/osutil"
  20. "github.com/syncthing/syncthing/internal/protocol"
  21. )
  22. var (
  23. Supported = true
  24. )
  25. func Read(path string) (string, uint32, error) {
  26. var mode uint32
  27. stat, err := os.Stat(path)
  28. if err != nil {
  29. mode = protocol.FlagSymlinkMissingTarget
  30. } else if stat.IsDir() {
  31. mode = protocol.FlagDirectory
  32. }
  33. path, err = os.Readlink(path)
  34. return osutil.NormalizedFilename(path), mode, err
  35. }
  36. func IsSymlink(path string) (bool, error) {
  37. lstat, err := os.Lstat(path)
  38. if err != nil {
  39. return false, err
  40. }
  41. return lstat.Mode()&os.ModeSymlink != 0, nil
  42. }
  43. func Create(source, target string, flags uint32) error {
  44. return os.Symlink(osutil.NativeFilename(target), source)
  45. }
  46. func ChangeType(path string, flags uint32) error {
  47. return nil
  48. }