stat.go 757 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package dirfs
  4. import (
  5. "context"
  6. "io/fs"
  7. "os"
  8. "tailscale.com/drive/driveimpl/shared"
  9. )
  10. // Stat implements webdav.FileSystem.
  11. func (dfs *FS) Stat(ctx context.Context, name string) (fs.FileInfo, error) {
  12. nameWithoutStaticRoot, isStaticRoot := dfs.trimStaticRoot(name)
  13. if isStaticRoot || shared.IsRoot(name) {
  14. // Static root is a directory, always use now() as the modified time to
  15. // bust caches.
  16. fi := shared.ReadOnlyDirInfo(name, dfs.now())
  17. return fi, nil
  18. }
  19. child := dfs.childFor(nameWithoutStaticRoot)
  20. if child == nil {
  21. return nil, &os.PathError{Op: "stat", Path: name, Err: os.ErrNotExist}
  22. }
  23. return shared.ReadOnlyDirInfo(name, dfs.now()), nil
  24. }