aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-23 00:06:24 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-23 00:06:24 -0700
commit654a69ff52a0625db174d7851463e3cc464ffe5a (patch)
treeca083db7d6b61ab217c0a3e81c3d8dc4b49fa4a8
parentc0f0fdb3baeb6e9852c6876b23c1404b2c5e833d (diff)
downloadseaweedfs-654a69ff52a0625db174d7851463e3cc464ffe5a.tar.xz
seaweedfs-654a69ff52a0625db174d7851463e3cc464ffe5a.zip
refactoring
-rw-r--r--weed/pb/filer_pb/filer_client.go (renamed from weed/pb/filer_pb/filer_client.pb.go)28
-rw-r--r--weed/s3api/filer_util.go24
-rw-r--r--weed/s3api/s3api_handlers.go4
3 files changed, 33 insertions, 23 deletions
diff --git a/weed/pb/filer_pb/filer_client.pb.go b/weed/pb/filer_pb/filer_client.go
index b2be614af..100e997b2 100644
--- a/weed/pb/filer_pb/filer_client.pb.go
+++ b/weed/pb/filer_pb/filer_client.go
@@ -92,3 +92,31 @@ func ReadDirAllEntries(filerClient FilerClient, fullDirPath util.FullPath, prefi
return
}
+
+func Exists(filerClient FilerClient, parentDirectoryPath string, entryName string, isDirectory bool) (exists bool, err error) {
+
+ err = filerClient.WithFilerClient(func(client SeaweedFilerClient) error {
+
+ request := &LookupDirectoryEntryRequest{
+ Directory: parentDirectoryPath,
+ Name: entryName,
+ }
+
+ glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)
+ resp, err := LookupEntry(client, request)
+ if err != nil {
+ if err == ErrNotFound {
+ exists = false
+ return nil
+ }
+ glog.V(0).Infof("exists entry %v: %v", request, err)
+ return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
+ }
+
+ exists = resp.Entry.IsDirectory == isDirectory
+
+ return nil
+ })
+
+ return
+}
diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go
index be985c893..2e738af50 100644
--- a/weed/s3api/filer_util.go
+++ b/weed/s3api/filer_util.go
@@ -153,30 +153,8 @@ func doDeleteEntry(client filer_pb.SeaweedFilerClient, parentDirectoryPath strin
func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isDirectory bool) (exists bool, err error) {
- err = s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
-
- request := &filer_pb.LookupDirectoryEntryRequest{
- Directory: parentDirectoryPath,
- Name: entryName,
- }
+ return filer_pb.Exists(s3a, parentDirectoryPath, entryName, isDirectory)
- glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)
- resp, err := filer_pb.LookupEntry(client, request)
- if err != nil {
- if err == filer_pb.ErrNotFound {
- exists = false
- return nil
- }
- glog.V(0).Infof("exists entry %v: %v", request, err)
- return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
- }
-
- exists = resp.Entry.IsDirectory == isDirectory
-
- return nil
- })
-
- return
}
func objectKey(key *string) *string {
diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.go
index d850cb088..05dd4b823 100644
--- a/weed/s3api/s3api_handlers.go
+++ b/weed/s3api/s3api_handlers.go
@@ -46,6 +46,10 @@ func (s3a *S3ApiServer) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) err
}, s3a.option.FilerGrpcAddress, s3a.option.GrpcDialOption)
}
+func (s3a *S3ApiServer) AdjustedUrl(hostAndPort string) string {
+ return hostAndPort
+}
+
// If none of the http routes match respond with MethodNotAllowed
func notFoundHandler(w http.ResponseWriter, r *http.Request) {