Browse Source

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
pull/664/head
Chris Lu 7 years ago
parent
commit
0301504184
  1. 5
      weed/command/filer_copy.go
  2. 13
      weed/filer2/abstract_sql/abstract_sql_store.go
  3. 11
      weed/filer2/cassandra/cassandra_store.go
  4. 1
      weed/filer2/entry.go
  5. 2
      weed/filer2/entry_codec.go
  6. 33
      weed/filer2/filer.go
  7. 2
      weed/filer2/filerstore.go
  8. 11
      weed/filer2/leveldb/leveldb_store.go
  9. 10
      weed/filer2/memdb/memdb_store.go
  10. 2
      weed/filer2/memdb/memdb_store_test.go
  11. 13
      weed/filer2/redis/redis_store.go
  12. 10
      weed/filesys/filehandle.go
  13. 3
      weed/operation/filer/register.go
  14. 1
      weed/pb/filer.proto
  15. 124
      weed/pb/filer_pb/filer.pb.go
  16. 13
      weed/server/filer_grpc_server.go
  17. 2
      weed/server/filer_server_handlers_admin.go
  18. 8
      weed/server/filer_server_handlers_read.go
  19. 9
      weed/server/filer_server_handlers_write.go
  20. 8
      weed/server/filer_ui/templates.go

5
weed/command/filer_copy.go

@ -174,7 +174,7 @@ func uploadFileAsOne(filerUrl string, urlFolder string, f *os.File, fi os.FileIn
fmt.Printf("uploaded %s to %s\n", f.Name(), targetUrl)
if err = filer_operation.RegisterFile(filerUrl, filepath.Join(urlFolder, f.Name()), assignResult.Fid, fi.Size(),
os.Getuid(), os.Getgid(), copy.secret); err != nil {
mimeType, os.Getuid(), os.Getgid(), copy.secret); err != nil {
fmt.Printf("Failed to register file %s on %s: %v\n", f.Name(), filerUrl, err)
return false
}
@ -185,6 +185,8 @@ func uploadFileAsOne(filerUrl string, urlFolder string, f *os.File, fi os.FileIn
func uploadFileInChunks(filerUrl string, urlFolder string, f *os.File, fi os.FileInfo, chunkCount int, chunkSize int64) bool {
mimeType := detectMimeType(f)
var chunks []*filer_pb.FileChunk
for i := int64(0); i < int64(chunkCount); i++ {
@ -235,6 +237,7 @@ func uploadFileInChunks(filerUrl string, urlFolder string, f *os.File, fi os.Fil
Uid: uint32(os.Getuid()),
FileSize: uint64(fi.Size()),
FileMode: uint32(fi.Mode()),
Mime: mimeType,
},
Chunks: chunks,
},

13
weed/filer2/abstract_sql/abstract_sql_store.go

@ -77,26 +77,21 @@ func (store *AbstractSqlStore) FindEntry(fullpath filer2.FullPath) (*filer2.Entr
return entry, nil
}
func (store *AbstractSqlStore) DeleteEntry(fullpath filer2.FullPath) (*filer2.Entry, error) {
entry, err := store.FindEntry(fullpath)
if err != nil {
return nil, nil
}
func (store *AbstractSqlStore) DeleteEntry(fullpath filer2.FullPath) (error) {
dir, name := fullpath.DirAndName()
res, err := store.DB.Exec(store.SqlDelete, hashToLong(dir), name, dir)
if err != nil {
return nil, fmt.Errorf("delete %s: %s", fullpath, err)
return fmt.Errorf("delete %s: %s", fullpath, err)
}
_, err = res.RowsAffected()
if err != nil {
return nil, fmt.Errorf("delete %s but no rows affected: %s", fullpath, err)
return fmt.Errorf("delete %s but no rows affected: %s", fullpath, err)
}
return entry, nil
return nil
}
func (store *AbstractSqlStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {

11
weed/filer2/cassandra/cassandra_store.go

@ -88,22 +88,17 @@ func (store *CassandraStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.
return entry, nil
}
func (store *CassandraStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
entry, err = store.FindEntry(fullpath)
if err != nil {
return nil, nil
}
func (store *CassandraStore) DeleteEntry(fullpath filer2.FullPath) error {
dir, name := fullpath.DirAndName()
if err := store.session.Query(
"DELETE FROM filemeta WHERE directory=? AND name=?",
dir, name).Exec(); err != nil {
return entry, fmt.Errorf("delete %s : %v", entry.FullPath, err)
return fmt.Errorf("delete %s : %v", fullpath, err)
}
return entry, nil
return nil
}
func (store *CassandraStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool,

1
weed/filer2/entry.go

@ -13,6 +13,7 @@ type Attr struct {
Mode os.FileMode // file mode
Uid uint32 // owner uid
Gid uint32 // group gid
Mime string
}
func (attr Attr) IsDirectory() bool {

2
weed/filer2/entry_codec.go

@ -17,6 +17,7 @@ func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) {
FileMode: uint32(entry.Attr.Mode),
Uid: entry.Uid,
Gid: entry.Gid,
Mime: entry.Mime,
},
Chunks: entry.Chunks,
}
@ -36,6 +37,7 @@ func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error {
entry.Attr.Mode = os.FileMode(message.Attributes.FileMode)
entry.Attr.Uid = message.Attributes.Uid
entry.Attr.Gid = message.Attributes.Gid
entry.Attr.Mime = message.Attributes.Mime
entry.Chunks = message.Chunks

33
weed/filer2/filer.go

@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"time"
"github.com/chrislusf/seaweedfs/weed/operation"
)
type Filer struct {
@ -101,6 +102,10 @@ func (f *Filer) CreateEntry(entry *Entry) error {
}
*/
if oldEntry, err := f.FindEntry(entry.FullPath); err == nil {
f.deleteChunks(oldEntry)
}
if err := f.store.InsertEntry(entry); err != nil {
return fmt.Errorf("insert entry %s: %v", entry.FullPath, err)
}
@ -116,26 +121,30 @@ func (f *Filer) FindEntry(p FullPath) (entry *Entry, err error) {
return f.store.FindEntry(p)
}
func (f *Filer) DeleteEntry(p FullPath) (fileEntry *Entry, err error) {
func (f *Filer) DeleteEntryMetaAndData(p FullPath) (err error) {
entry, err := f.FindEntry(p)
if err != nil {
return nil, err
return err
}
if entry.IsDirectory() {
entries, err := f.ListDirectoryEntries(p, "", false, 1)
if err != nil {
return nil, fmt.Errorf("list folder %s: %v", p, err)
return fmt.Errorf("list folder %s: %v", p, err)
}
if len(entries) > 0 {
return nil, fmt.Errorf("folder %s is not empty", p)
return fmt.Errorf("folder %s is not empty", p)
}
}
f.deleteChunks(entry)
return f.store.DeleteEntry(p)
}
func (f *Filer) ListDirectoryEntries(p FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error) {
if strings.HasSuffix(string(p), "/") && len(p) > 1 {
p = p[0 : len(p)-1]
p = p[0: len(p)-1]
}
return f.store.ListDirectoryEntries(p, startFileName, inclusive, limit)
}
@ -164,3 +173,17 @@ func (f *Filer) cacheSetDirectory(dirpath string, dirEntry *Entry, level int) {
f.directoryCache.Set(dirpath, dirEntry, time.Duration(minutes)*time.Minute)
}
func (f *Filer) deleteChunks(entry *Entry) {
if f.master == "" {
return
}
if entry == nil {
return
}
for _, chunk := range entry.Chunks {
if err := operation.DeleteFile(f.master, chunk.FileId, ""); err != nil {
glog.V(0).Infof("deleting file %s: %v", chunk.FileId, err)
}
}
}

2
weed/filer2/filerstore.go

@ -11,7 +11,7 @@ type FilerStore interface {
InsertEntry(*Entry) error
UpdateEntry(*Entry) (err error)
FindEntry(FullPath) (entry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error)
DeleteEntry(FullPath) (err error)
ListDirectoryEntries(dirPath FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error)
}

11
weed/filer2/leveldb/leveldb_store.go

@ -93,20 +93,15 @@ func (store *LevelDBStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.En
return entry, nil
}
func (store *LevelDBStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
func (store *LevelDBStore) DeleteEntry(fullpath filer2.FullPath) (err error) {
key := genKey(fullpath.DirAndName())
entry, err = store.FindEntry(fullpath)
if err != nil {
return nil, nil
}
err = store.db.Delete(key, nil)
if err != nil {
return entry, fmt.Errorf("delete %s : %v", entry.FullPath, err)
return fmt.Errorf("delete %s : %v", fullpath, err)
}
return entry, nil
return nil
}
func (store *LevelDBStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool,

10
weed/filer2/memdb/memdb_store.go

@ -56,13 +56,9 @@ func (store *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entr
return entry, nil
}
func (store *MemDbStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
item := store.tree.Delete(entryItem{&filer2.Entry{FullPath: fullpath}})
if item == nil {
return nil, nil
}
entry = item.(entryItem).Entry
return entry, nil
func (store *MemDbStore) DeleteEntry(fullpath filer2.FullPath) (err error) {
store.tree.Delete(entryItem{&filer2.Entry{FullPath: fullpath}})
return nil
}
func (store *MemDbStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {

2
weed/filer2/memdb/memdb_store_test.go

@ -134,7 +134,7 @@ func TestCreateFileAndList(t *testing.T) {
}
// delete file and count
filer.DeleteEntry(file3Path)
filer.DeleteEntryMetaAndData(file3Path)
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
if len(entries) != 1 {
t.Errorf("list entries count: %v", len(entries))

13
weed/filer2/redis/redis_store.go

@ -94,28 +94,23 @@ func (store *RedisStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entr
return entry, nil
}
func (store *RedisStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
entry, err = store.FindEntry(fullpath)
if err != nil {
return nil, nil
}
func (store *RedisStore) DeleteEntry(fullpath filer2.FullPath) (err error) {
_, err = store.Client.Del(string(fullpath)).Result()
if err != nil {
return entry, fmt.Errorf("delete %s : %v", entry.FullPath, err)
return fmt.Errorf("delete %s : %v", fullpath, err)
}
dir, name := fullpath.DirAndName()
if name != "" {
_, err = store.Client.SRem(genDirectoryListKey(dir), name).Result()
if err != nil {
return nil, fmt.Errorf("delete %s in parent dir: %v", entry.FullPath, err)
return fmt.Errorf("delete %s in parent dir: %v", fullpath, err)
}
}
return entry, nil
return nil
}
func (store *RedisStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool,

10
weed/filesys/filehandle.go

@ -11,6 +11,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/util"
"strings"
"sync"
"net/http"
)
type FileHandle struct {
@ -18,10 +19,6 @@ type FileHandle struct {
dirtyPages *ContinuousDirtyPages
dirtyMetadata bool
cachePath string
handle uint64
f *File
RequestId fuse.RequestID // unique ID for request
NodeId fuse.NodeID // file or directory the request is about
@ -135,6 +132,11 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f
resp.Size = len(req.Data)
if req.Offset == 0 {
fh.f.attributes.Mime = http.DetectContentType(req.Data)
fh.dirtyMetadata = true
}
if chunk != nil {
fh.f.Chunks = append(fh.f.Chunks, chunk)
glog.V(1).Infof("uploaded %s/%s to %s [%d,%d)", fh.f.dir.Path, fh.f.Name, chunk.FileId, chunk.Offset, chunk.Offset+int64(chunk.Size))

3
weed/operation/filer/register.go

@ -17,7 +17,7 @@ type SubmitResult struct {
Error string `json:"error,omitempty"`
}
func RegisterFile(filer string, path string, fileId string, fileSize int64, uid, gid int, secret security.Secret) error {
func RegisterFile(filer string, path string, fileId string, fileSize int64, mime string, uid, gid int, secret security.Secret) error {
// TODO: jwt need to be used
_ = security.GenJwt(secret, fileId)
@ -27,6 +27,7 @@ func RegisterFile(filer string, path string, fileId string, fileSize int64, uid,
values.Add("fileSize", strconv.FormatInt(fileSize, 10))
values.Add("uid", strconv.Itoa(uid))
values.Add("gid", strconv.Itoa(gid))
values.Add("mime", mime)
_, err := util.Post("http://"+filer+"/admin/register", values)
if err != nil {
return fmt.Errorf("Failed to register path %s on filer %s to file id %s : %v", path, filer, fileId, err)

1
weed/pb/filer.proto

@ -72,6 +72,7 @@ message FuseAttributes {
uint32 uid = 4;
uint32 gid = 5;
int64 crtime = 6;
string mime = 7;
}
message GetEntryAttributesRequest {

124
weed/pb/filer_pb/filer.pb.go

@ -214,6 +214,7 @@ type FuseAttributes struct {
Uid uint32 `protobuf:"varint,4,opt,name=uid" json:"uid,omitempty"`
Gid uint32 `protobuf:"varint,5,opt,name=gid" json:"gid,omitempty"`
Crtime int64 `protobuf:"varint,6,opt,name=crtime" json:"crtime,omitempty"`
Mime string `protobuf:"bytes,7,opt,name=mime" json:"mime,omitempty"`
}
func (m *FuseAttributes) Reset() { *m = FuseAttributes{} }
@ -263,6 +264,13 @@ func (m *FuseAttributes) GetCrtime() int64 {
return 0
}
func (m *FuseAttributes) GetMime() string {
if m != nil {
return m.Mime
}
return ""
}
type GetEntryAttributesRequest struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
ParentDir string `protobuf:"bytes,2,opt,name=parent_dir,json=parentDir" json:"parent_dir,omitempty"`
@ -931,62 +939,62 @@ var _SeaweedFiler_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("filer.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 899 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0xdd, 0x6e, 0xdc, 0x44,
0x14, 0x8e, 0xd7, 0xf1, 0x26, 0x3e, 0xbb, 0xe1, 0x67, 0x36, 0x2d, 0x66, 0x9b, 0x54, 0x61, 0xa0,
0xa8, 0x15, 0x52, 0x14, 0x05, 0x2e, 0x2a, 0x10, 0x12, 0x55, 0x53, 0xaa, 0x4a, 0xa9, 0x2a, 0xb9,
0x04, 0x89, 0xab, 0x95, 0x63, 0x9f, 0x5d, 0x46, 0xf1, 0xda, 0xc6, 0x33, 0x0e, 0x0a, 0xb7, 0xbc,
0x06, 0xb7, 0xbc, 0x01, 0x6f, 0xc0, 0x8b, 0xa1, 0xf9, 0xb1, 0x3d, 0x8e, 0xbd, 0xfd, 0xb9, 0xe0,
0x6e, 0xe6, 0xfc, 0x7c, 0xe7, 0x3b, 0x33, 0x67, 0x3e, 0x1b, 0x26, 0x4b, 0x96, 0x62, 0x79, 0x5c,
0x94, 0xb9, 0xc8, 0xc9, 0xae, 0xda, 0x2c, 0x8a, 0x4b, 0xfa, 0x0a, 0xee, 0x9d, 0xe7, 0xf9, 0x55,
0x55, 0x9c, 0xb1, 0x12, 0x63, 0x91,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 0x30, 0xb5, 0x45, 0x80, 0x58, 0x09, 0x03, 0x5a, 0x34, 0xbf, 0xbf, 0xc9,
0x6d, 0x03, 0xda, 0x33, 0x6f, 0x03, 0x0e, 0xbc, 0x7a, 0x1b, 0x70, 0xe8, 0xa9, 0xd0, 0xad, 0xcb,
0xb1, 0xfa, 0x3d, 0xfd, 0xfa, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83, 0x92, 0xde, 0x64, 0xad,
0x0a, 0x00, 0x00,
// 906 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0x5b, 0x6f, 0xdc, 0x44,
0x14, 0x8e, 0xd7, 0xd9, 0x4d, 0x7c, 0x76, 0xc3, 0x65, 0x36, 0x2d, 0x66, 0x9b, 0x54, 0x61, 0xa0,
0xa8, 0x15, 0x52, 0x14, 0x05, 0x1e, 0x2a, 0x10, 0x12, 0x55, 0x53, 0xaa, 0x4a, 0xa9, 0x2a, 0xb9,
0x04, 0x89, 0xa7, 0x95, 0x63, 0x9f, 0x5d, 0x46, 0xf1, 0x0d, 0xcf, 0x38, 0x28, 0xbc, 0xf2, 0x5b,
0x78, 0xe7, 0x81, 0x7f, 0xc0, 0x1f, 0x43, 0x73, 0xb1, 0x3d, 0x8e, 0xbd, 0xbd, 0x3c, 0xf0, 0x36,
0x73, 0x2e, 0xdf, 0xf9, 0xce, 0xcc, 0x99, 0xcf, 0x86, 0xe9, 0x8a, 0x25, 0x58, 0x1e, 0x17, 0x65,
0x2e, 0x72, 0xb2, 0xab, 0x36, 0xcb, 0xe2, 0x92, 0xbe, 0x82, 0x7b, 0xe7, 0x79, 0x7e, 0x55, 0x15,
0x67, 0xac, 0xc4, 0x48, 0xe4, 0xe5, 0xcd, 0xb3, 0x4c, 0x94, 0x37, 0x01, 0xfe, 0x56, 0x21, 0x17,
0xe4, 0x00, 0xbc, 0xb8, 0x76, 0xf8, 0x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, 0xb9, 0x6d, 0x40, 0x7b, 0xe6, 0x6d, 0xc0, 0x81, 0x57,
0x6f, 0x03, 0x0e, 0x3d, 0x15, 0xba, 0x75, 0x39, 0x51, 0xbf, 0xac, 0x5f, 0xff, 0x17, 0x00, 0x00,
0xff, 0xff, 0xf1, 0x42, 0x51, 0xbb, 0xc1, 0x0a, 0x00, 0x00,
}

13
weed/server/filer_grpc_server.go

@ -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
}

2
weed/server/filer_server_handlers_admin.go

@ -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,

8
weed/server/filer_server_handlers_read.go

@ -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)

9
weed/server/filer_server_handlers_write.go

@ -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": ""})
}

8
weed/server/filer_ui/templates.go

@ -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
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
{{end}}
</td>
<td>

Loading…
Cancel
Save