mounted_file_system.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2015 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fuse
  15. import "golang.org/x/net/context"
  16. // MountedFileSystem represents the status of a mount operation, with a method
  17. // that waits for unmounting.
  18. type MountedFileSystem struct {
  19. dir string
  20. // The result to return from Join. Not valid until the channel is closed.
  21. joinStatus error
  22. joinStatusAvailable chan struct{}
  23. }
  24. // Dir returns the directory on which the file system is mounted (or where we
  25. // attempted to mount it.)
  26. func (mfs *MountedFileSystem) Dir() string {
  27. return mfs.dir
  28. }
  29. // Join blocks until a mounted file system has been unmounted. It does not
  30. // return successfully until all ops read from the connection have been
  31. // responded to (i.e. the file system server has finished processing all
  32. // in-flight ops).
  33. //
  34. // The return value will be non-nil if anything unexpected happened while
  35. // serving. May be called multiple times.
  36. func (mfs *MountedFileSystem) Join(ctx context.Context) error {
  37. select {
  38. case <-mfs.joinStatusAvailable:
  39. return mfs.joinStatus
  40. case <-ctx.Done():
  41. return ctx.Err()
  42. }
  43. }