2021-07-29 05:43:12 +00:00
|
|
|
package filer
|
|
|
|
|
|
|
|
import (
|
2021-08-09 21:35:18 +00:00
|
|
|
"context"
|
2021-07-29 05:43:12 +00:00
|
|
|
"fmt"
|
2021-07-29 09:08:55 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2021-08-09 21:35:18 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2021-07-29 05:43:12 +00:00
|
|
|
)
|
|
|
|
|
2021-08-01 06:52:09 +00:00
|
|
|
func (entry *Entry) IsInRemoteOnly() bool {
|
2021-08-09 21:35:18 +00:00
|
|
|
return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.RemoteSize > 0
|
2021-07-29 05:43:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 05:30:36 +00:00
|
|
|
func (f *Filer) ReadRemote(entry *Entry, offset int64, size int64) (data []byte, err error) {
|
2021-07-29 09:08:55 +00:00
|
|
|
client, _, found := f.RemoteStorage.GetRemoteStorageClient(entry.Remote.StorageName)
|
2021-07-29 05:43:12 +00:00
|
|
|
if !found {
|
2021-08-01 05:39:38 +00:00
|
|
|
return nil, fmt.Errorf("remote storage %v not found", entry.Remote.StorageName)
|
2021-07-29 05:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mountDir, remoteLoation := f.RemoteStorage.FindMountDirectory(entry.FullPath)
|
|
|
|
|
2021-08-09 21:35:18 +00:00
|
|
|
sourceLoc := MapFullPathToRemoteStorageLocation(mountDir, remoteLoation, entry.FullPath)
|
2021-07-29 05:43:12 +00:00
|
|
|
|
2021-08-09 21:35:18 +00:00
|
|
|
return client.ReadFile(sourceLoc, offset, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func MapFullPathToRemoteStorageLocation(localMountedDir util.FullPath, remoteMountedLocation *filer_pb.RemoteStorageLocation, fp util.FullPath) *filer_pb.RemoteStorageLocation {
|
|
|
|
remoteLocation := &filer_pb.RemoteStorageLocation{
|
|
|
|
Name: remoteMountedLocation.Name,
|
|
|
|
Bucket: remoteMountedLocation.Bucket,
|
|
|
|
Path: remoteMountedLocation.Path,
|
2021-07-29 09:08:55 +00:00
|
|
|
}
|
2021-08-15 08:53:46 +00:00
|
|
|
remoteLocation.Path = string(util.FullPath(remoteLocation.Path).Child(string(fp)[len(localMountedDir):]))
|
2021-08-09 21:35:18 +00:00
|
|
|
return remoteLocation
|
|
|
|
}
|
2021-07-29 05:43:12 +00:00
|
|
|
|
2021-08-15 08:53:46 +00:00
|
|
|
func MapRemoteStorageLocationPathToFullPath(localMountedDir util.FullPath, remoteMountedLocation *filer_pb.RemoteStorageLocation, remoteLocationPath string)(fp util.FullPath) {
|
|
|
|
return localMountedDir.Child(remoteLocationPath[len(remoteMountedLocation.Path):])
|
|
|
|
}
|
|
|
|
|
2021-08-09 21:35:18 +00:00
|
|
|
func DownloadToLocal(filerClient filer_pb.FilerClient, remoteConf *filer_pb.RemoteConf, remoteLocation *filer_pb.RemoteStorageLocation, parent util.FullPath, entry *filer_pb.Entry) error {
|
|
|
|
return filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
_, err := client.DownloadToLocal(context.Background(), &filer_pb.DownloadToLocalRequest{
|
|
|
|
Directory: string(parent),
|
|
|
|
Name: entry.Name,
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
2021-07-29 05:43:12 +00:00
|
|
|
}
|