aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-09-14 13:07:40 -0700
committerChris Lu <chris.lu@gmail.com>2020-09-14 13:07:46 -0700
commitada996fe559103a64de9f053e20ef625b0e0cb74 (patch)
tree8f1f82e9d2da550d3de673f915813d7a1b2f1a4c
parent8aaae78dfcb455ed70f5674636d8e5250d5b229a (diff)
downloadseaweedfs-ada996fe559103a64de9f053e20ef625b0e0cb74.tar.xz
seaweedfs-ada996fe559103a64de9f053e20ef625b0e0cb74.zip
filer: support createing empty folder
fix https://github.com/chrislusf/seaweedfs/issues/1161
-rw-r--r--weed/server/filer_server_handlers_write_autochunk.go56
1 files changed, 55 insertions, 1 deletions
diff --git a/weed/server/filer_server_handlers_write_autochunk.go b/weed/server/filer_server_handlers_write_autochunk.go
index 0f6176356..5c551588c 100644
--- a/weed/server/filer_server_handlers_write_autochunk.go
+++ b/weed/server/filer_server_handlers_write_autochunk.go
@@ -3,6 +3,7 @@ package weed_server
import (
"context"
"crypto/md5"
+ "fmt"
"hash"
"io"
"io/ioutil"
@@ -46,7 +47,11 @@ func (fs *FilerServer) autoChunk(ctx context.Context, w http.ResponseWriter, r *
var err error
var md5bytes []byte
if r.Method == "POST" {
- reply, md5bytes, err = fs.doPostAutoChunk(ctx, w, r, chunkSize, replication, collection, dataCenter, ttlSec, ttlString, fsync)
+ if r.Header.Get("Content-Type") == "" && strings.HasSuffix(r.URL.Path, "/") {
+ reply, err = fs.mkdir(ctx, w, r)
+ } else {
+ reply, md5bytes, err = fs.doPostAutoChunk(ctx, w, r, chunkSize, replication, collection, dataCenter, ttlSec, ttlString, fsync)
+ }
} else {
reply, md5bytes, err = fs.doPutAutoChunk(ctx, w, r, chunkSize, replication, collection, dataCenter, ttlSec, ttlString, fsync)
}
@@ -254,3 +259,52 @@ func (fs *FilerServer) saveAsChunk(replication string, collection string, dataCe
return uploadResult.ToPbFileChunk(fileId, offset), collection, replication, nil
}
}
+
+func (fs *FilerServer) mkdir(ctx context.Context, w http.ResponseWriter, r *http.Request) (filerResult *FilerPostResult, replyerr error) {
+
+ // detect file mode
+ modeStr := r.URL.Query().Get("mode")
+ if modeStr == "" {
+ modeStr = "0660"
+ }
+ mode, err := strconv.ParseUint(modeStr, 8, 32)
+ if err != nil {
+ glog.Errorf("Invalid mode format: %s, use 0660 by default", modeStr)
+ mode = 0660
+ }
+
+ // fix the path
+ path := r.URL.Path
+ if strings.HasSuffix(path, "/") {
+ path = path[:len(path)-1]
+ }
+
+ existingEntry, err := fs.filer.FindEntry(ctx, util.FullPath(path))
+ if err == nil && existingEntry != nil {
+ replyerr = fmt.Errorf("dir %s already exists", path)
+ return
+ }
+
+ glog.V(4).Infoln("mkdir", path)
+ entry := &filer.Entry{
+ FullPath: util.FullPath(path),
+ Attr: filer.Attr{
+ Mtime: time.Now(),
+ Crtime: time.Now(),
+ Mode: os.FileMode(mode) | os.ModeDir,
+ Uid: OS_UID,
+ Gid: OS_GID,
+ },
+ }
+
+ filerResult = &FilerPostResult{
+ Name: util.FullPath(path).Name(),
+ }
+
+ if dbErr := fs.filer.CreateEntry(ctx, entry, false, false, nil); dbErr != nil {
+ replyerr = dbErr
+ filerResult.Error = dbErr.Error()
+ glog.V(0).Infof("failing to create dir %s on filer server : %v", path, dbErr)
+ }
+ return filerResult, replyerr
+}