basicfs_unix.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 https://mozilla.org/MPL/2.0/.
  6. // +build !windows
  7. package fs
  8. import "os"
  9. func (BasicFilesystem) SymlinksSupported() bool {
  10. return true
  11. }
  12. func (f *BasicFilesystem) CreateSymlink(target, name string) error {
  13. name, err := f.rooted(name)
  14. if err != nil {
  15. return err
  16. }
  17. return os.Symlink(target, name)
  18. }
  19. func (f *BasicFilesystem) ReadSymlink(name string) (string, error) {
  20. name, err := f.rooted(name)
  21. if err != nil {
  22. return "", err
  23. }
  24. return os.Readlink(name)
  25. }
  26. func (f *BasicFilesystem) MkdirAll(name string, perm FileMode) error {
  27. name, err := f.rooted(name)
  28. if err != nil {
  29. return err
  30. }
  31. return os.MkdirAll(name, os.FileMode(perm))
  32. }
  33. // Unhide is a noop on unix, as unhiding files requires renaming them.
  34. // We still check that the relative path does not try to escape the root
  35. func (f *BasicFilesystem) Unhide(name string) error {
  36. _, err := f.rooted(name)
  37. return err
  38. }
  39. // Hide is a noop on unix, as hiding files requires renaming them.
  40. // We still check that the relative path does not try to escape the root
  41. func (f *BasicFilesystem) Hide(name string) error {
  42. _, err := f.rooted(name)
  43. return err
  44. }
  45. func (f *BasicFilesystem) Roots() ([]string, error) {
  46. return []string{"/"}, nil
  47. }