add mime, use simple insert and update filer store API
1. add mime type to file in filer 2. purge old chunks if overwrite during insert
This commit is contained in:
@@ -50,6 +50,7 @@ func (fs *FilerServer) ListEntries(ctx context.Context, req *filer_pb.ListEntrie
|
||||
Gid: entry.Gid,
|
||||
Uid: entry.Uid,
|
||||
FileMode: uint32(entry.Mode),
|
||||
Mime: entry.Mime,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -75,6 +76,7 @@ func (fs *FilerServer) GetEntryAttributes(ctx context.Context, req *filer_pb.Get
|
||||
attributes.Gid = entry.Gid
|
||||
attributes.Mtime = entry.Mtime.Unix()
|
||||
attributes.Crtime = entry.Crtime.Unix()
|
||||
attributes.Mime = entry.Mime
|
||||
|
||||
glog.V(3).Infof("GetEntryAttributes %v size %d chunks %d: %+v", fullpath, attributes.FileSize, len(entry.Chunks), attributes)
|
||||
|
||||
@@ -120,6 +122,7 @@ func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntr
|
||||
Mode: os.FileMode(req.Entry.Attributes.FileMode),
|
||||
Uid: req.Entry.Attributes.Uid,
|
||||
Gid: req.Entry.Attributes.Gid,
|
||||
Mime: req.Entry.Attributes.Mime,
|
||||
},
|
||||
Chunks: req.Entry.Chunks,
|
||||
})
|
||||
@@ -162,6 +165,7 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr
|
||||
}
|
||||
newEntry.Attr.Uid = req.Entry.Attributes.Uid
|
||||
newEntry.Attr.Gid = req.Entry.Attributes.Gid
|
||||
newEntry.Attr.Mime = req.Entry.Attributes.Mime
|
||||
|
||||
}
|
||||
|
||||
@@ -180,14 +184,7 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr
|
||||
}
|
||||
|
||||
func (fs *FilerServer) DeleteEntry(ctx context.Context, req *filer_pb.DeleteEntryRequest) (resp *filer_pb.DeleteEntryResponse, err error) {
|
||||
entry, err := fs.filer.DeleteEntry(filer2.FullPath(filepath.Join(req.Directory, req.Name)))
|
||||
if err == nil {
|
||||
for _, chunk := range entry.Chunks {
|
||||
if err = operation.DeleteFile(fs.getMasterNode(), chunk.FileId, fs.jwt(chunk.FileId)); err != nil {
|
||||
glog.V(0).Infof("deleting file %s: %v", chunk.FileId, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
err = fs.filer.DeleteEntryMetaAndData(filer2.FullPath(filepath.Join(req.Directory, req.Name)))
|
||||
return &filer_pb.DeleteEntryResponse{}, err
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("parsing gid: %v", err))
|
||||
return
|
||||
}
|
||||
mime := r.FormValue("mime")
|
||||
entry := &filer2.Entry{
|
||||
FullPath: filer2.FullPath(path),
|
||||
Attr: filer2.Attr{
|
||||
@@ -40,6 +41,7 @@ func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
Mtime: time.Now(),
|
||||
Uid: uint32(uid),
|
||||
Gid: uint32(gid),
|
||||
Mime: mime,
|
||||
},
|
||||
Chunks: []*filer_pb.FileChunk{{
|
||||
FileId: fileId,
|
||||
|
||||
@@ -111,9 +111,11 @@ func (fs *FilerServer) handleSingleChunk(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
func (fs *FilerServer) handleMultipleChunks(w http.ResponseWriter, r *http.Request, entry *filer2.Entry) {
|
||||
|
||||
mimeType := ""
|
||||
if ext := path.Ext(entry.Name()); ext != "" {
|
||||
mimeType = mime.TypeByExtension(ext)
|
||||
mimeType := entry.Mime
|
||||
if mimeType == "" {
|
||||
if ext := path.Ext(entry.Name()); ext != "" {
|
||||
mimeType = mime.TypeByExtension(ext)
|
||||
}
|
||||
}
|
||||
if mimeType != "" {
|
||||
w.Header().Set("Content-Type", mimeType)
|
||||
|
||||
@@ -195,19 +195,12 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// curl -X DELETE http://localhost:8888/path/to
|
||||
func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
entry, err := fs.filer.DeleteEntry(filer2.FullPath(r.URL.Path))
|
||||
err := fs.filer.DeleteEntryMetaAndData(filer2.FullPath(r.URL.Path))
|
||||
if err != nil {
|
||||
glog.V(4).Infoln("deleting", r.URL.Path, ":", err.Error())
|
||||
writeJsonError(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry != nil && !entry.IsDirectory() {
|
||||
for _, chunk := range entry.Chunks {
|
||||
oldFid := chunk.FileId
|
||||
operation.DeleteFile(fs.getMasterNode(), oldFid, fs.jwt(oldFid))
|
||||
}
|
||||
}
|
||||
|
||||
writeJsonQuiet(w, r, http.StatusAccepted, map[string]string{"error": ""})
|
||||
}
|
||||
|
||||
@@ -47,9 +47,15 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html>
|
||||
</td>
|
||||
<td align="right">
|
||||
{{if $entry.IsDirectory}}
|
||||
{{else}}
|
||||
{{ $entry.Mime }}
|
||||
{{end}}
|
||||
</td>
|
||||
<td align="right">
|
||||
{{if $entry.IsDirectory}}
|
||||
{{else}}
|
||||
{{ $entry.Size }} bytes
|
||||
|
||||
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user