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.

37 lines
1.1 KiB

3 years ago
  1. package filer
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  5. "github.com/chrislusf/seaweedfs/weed/pb/remote_pb"
  6. )
  7. func SaveMountMapping(filerClient filer_pb.FilerClient, dir string, remoteStorageLocation *remote_pb.RemoteStorageLocation) (err error) {
  8. // read current mapping
  9. var oldContent, newContent []byte
  10. err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  11. oldContent, err = ReadInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE)
  12. return err
  13. })
  14. if err != nil {
  15. if err != filer_pb.ErrNotFound {
  16. return fmt.Errorf("read existing mapping: %v", err)
  17. }
  18. }
  19. // add new mapping
  20. newContent, err = AddRemoteStorageMapping(oldContent, dir, remoteStorageLocation)
  21. if err != nil {
  22. return fmt.Errorf("add mapping %s~%s: %v", dir, remoteStorageLocation, err)
  23. }
  24. // save back
  25. err = filerClient.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  26. return SaveInsideFiler(client, DirectoryEtcRemote, REMOTE_STORAGE_MOUNT_FILE, newContent)
  27. })
  28. if err != nil {
  29. return fmt.Errorf("save mapping: %v", err)
  30. }
  31. return nil
  32. }