mkdir.go 793 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package dirfs
  4. import (
  5. "context"
  6. "os"
  7. "tailscale.com/drive/driveimpl/shared"
  8. )
  9. // Mkdir implements webdav.FileSystem. All attempts to Mkdir a directory that
  10. // already exists will succeed. All other attempts will fail with
  11. // os.ErrPermission.
  12. func (dfs *FS) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
  13. nameWithoutStaticRoot, isStaticRoot := dfs.trimStaticRoot(name)
  14. if isStaticRoot || shared.IsRoot(name) {
  15. // root directory already exists, consider this okay
  16. return nil
  17. }
  18. child := dfs.childFor(nameWithoutStaticRoot)
  19. if child != nil {
  20. // child already exists, consider this okay
  21. return nil
  22. }
  23. return &os.PathError{Op: "mkdir", Path: name, Err: os.ErrPermission}
  24. }