diff options
Diffstat (limited to 'weed/filer')
| -rw-r--r-- | weed/filer/entry.go | 17 | ||||
| -rw-r--r-- | weed/filer/read_remote.go | 30 |
2 files changed, 40 insertions, 7 deletions
diff --git a/weed/filer/entry.go b/weed/filer/entry.go index 7673365fb..8fa75fe6b 100644 --- a/weed/filer/entry.go +++ b/weed/filer/entry.go @@ -57,6 +57,23 @@ func (entry *Entry) Timestamp() time.Time { } } +func (entry *Entry) ShallowClone() *Entry { + if entry == nil { + return nil + } + newEntry := &Entry{} + newEntry.FullPath = entry.FullPath + newEntry.Attr = entry.Attr + newEntry.Chunks = entry.Chunks + newEntry.Extended = entry.Extended + newEntry.HardLinkId = entry.HardLinkId + newEntry.HardLinkCounter = entry.HardLinkCounter + newEntry.Content = entry.Content + newEntry.Remote = entry.Remote + + return newEntry +} + func (entry *Entry) ToProtoEntry() *filer_pb.Entry { if entry == nil { return nil diff --git a/weed/filer/read_remote.go b/weed/filer/read_remote.go index 8636a5c20..77ca81f15 100644 --- a/weed/filer/read_remote.go +++ b/weed/filer/read_remote.go @@ -1,12 +1,14 @@ package filer import ( + "context" "fmt" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "github.com/chrislusf/seaweedfs/weed/util" ) func (entry *Entry) IsInRemoteOnly() bool { - return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.Size > 0 + return len(entry.Chunks) == 0 && entry.Remote != nil && entry.Remote.RemoteSize > 0 } func (f *Filer) ReadRemote(entry *Entry, offset int64, size int64) (data []byte, err error) { @@ -17,13 +19,27 @@ func (f *Filer) ReadRemote(entry *Entry, offset int64, size int64) (data []byte, mountDir, remoteLoation := f.RemoteStorage.FindMountDirectory(entry.FullPath) - remoteFullPath := remoteLoation.Path + string(entry.FullPath[len(mountDir):]) + sourceLoc := MapFullPathToRemoteStorageLocation(mountDir, remoteLoation, entry.FullPath) - sourceLoc := &filer_pb.RemoteStorageLocation{ - Name: remoteLoation.Name, - Bucket: remoteLoation.Bucket, - Path: remoteFullPath, + 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, } + remoteLocation.Path += string(fp)[len(localMountedDir):] + return remoteLocation +} - return client.ReadFile(sourceLoc, offset, size) +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 + }) } |
