diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-09-04 05:02:20 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-09-04 05:02:20 -0700 |
| commit | 8707ef00a6ccfc387c83c886de379aa8ad948caa (patch) | |
| tree | 674184808f9e9f9915433bc16c30baf829a7c67c /weed/filer/remote_mapping.go | |
| parent | 13cc2ef723f3d19c2bf83ab8b084c6bfcd59c8ee (diff) | |
| download | seaweedfs-8707ef00a6ccfc387c83c886de379aa8ad948caa.tar.xz seaweedfs-8707ef00a6ccfc387c83c886de379aa8ad948caa.zip | |
refactor
Diffstat (limited to 'weed/filer/remote_mapping.go')
| -rw-r--r-- | weed/filer/remote_mapping.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/weed/filer/remote_mapping.go b/weed/filer/remote_mapping.go new file mode 100644 index 000000000..c23a60422 --- /dev/null +++ b/weed/filer/remote_mapping.go @@ -0,0 +1,38 @@ +package filer + +import ( + "fmt" + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "github.com/chrislusf/seaweedfs/weed/pb/remote_pb" +) + +func SaveMountMapping(filerClient filer_pb.FilerClient, dir string, remoteStorageLocation *remote_pb.RemoteStorageLocation) (err error) { + + // read current mapping + var oldContent, newContent []byte + err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { + oldContent, err = ReadInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE) + return err + }) + if err != nil { + if err != filer_pb.ErrNotFound { + return fmt.Errorf("read existing mapping: %v", err) + } + } + + // add new mapping + newContent, err = AddRemoteStorageMapping(oldContent, dir, remoteStorageLocation) + if err != nil { + return fmt.Errorf("add mapping %s~%s: %v", dir, remoteStorageLocation, err) + } + + // save back + err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { + return SaveInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE, newContent) + }) + if err != nil { + return fmt.Errorf("save mapping: %v", err) + } + + return nil +}
\ No newline at end of file |
