You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

3 years ago
3 years ago
  1. package filer
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. )
  8. func (entry *Entry) IsInRemoteOnly() bool {
  9. return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.RemoteSize > 0
  10. }
  11. func (f *Filer) ReadRemote(entry *Entry, offset int64, size int64) (data []byte, err error) {
  12. client, _, found := f.RemoteStorage.GetRemoteStorageClient(entry.Remote.StorageName)
  13. if !found {
  14. return nil, fmt.Errorf("remote storage %v not found", entry.Remote.StorageName)
  15. }
  16. mountDir, remoteLoation := f.RemoteStorage.FindMountDirectory(entry.FullPath)
  17. sourceLoc := MapFullPathToRemoteStorageLocation(mountDir, remoteLoation, entry.FullPath)
  18. return client.ReadFile(sourceLoc, offset, size)
  19. }
  20. func MapFullPathToRemoteStorageLocation(localMountedDir util.FullPath, remoteMountedLocation *filer_pb.RemoteStorageLocation, fp util.FullPath) *filer_pb.RemoteStorageLocation {
  21. remoteLocation := &filer_pb.RemoteStorageLocation{
  22. Name: remoteMountedLocation.Name,
  23. Bucket: remoteMountedLocation.Bucket,
  24. Path: remoteMountedLocation.Path,
  25. }
  26. remoteLocation.Path += string(fp)[len(localMountedDir):]
  27. return remoteLocation
  28. }
  29. func DownloadToLocal(filerClient filer_pb.FilerClient, remoteConf *filer_pb.RemoteConf, remoteLocation *filer_pb.RemoteStorageLocation, parent util.FullPath, entry *filer_pb.Entry) error {
  30. return filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  31. _, err := client.DownloadToLocal(context.Background(), &filer_pb.DownloadToLocalRequest{
  32. Directory: string(parent),
  33. Name: entry.Name,
  34. })
  35. return err
  36. })
  37. }