Browse Source

remove nlink property from directory node

pull/655/head
Chris Lu 7 years ago
parent
commit
fc7f81f6e7
  1. 4
      weed/filer2/filer.go
  2. 2
      weed/filer2/filer_structure.go
  3. 5
      weed/filer2/memdb/memdb_store.go
  4. 11
      weed/filer2/memdb/memdb_store_test.go

4
weed/filer2/filer.go

@ -71,7 +71,6 @@ func (f *Filer) CreateEntry(entry *Entry) (error) {
Mode: os.ModeDir | 0660, Mode: os.ModeDir | 0660,
Uid: entry.Uid, Uid: entry.Uid,
Gid: entry.Gid, Gid: entry.Gid,
Nlink: 2,
}, },
} }
@ -102,9 +101,6 @@ func (f *Filer) CreateEntry(entry *Entry) (error) {
if err := f.store.InsertEntry(entry); err != nil { if err := f.store.InsertEntry(entry); err != nil {
return fmt.Errorf("insert entry %s: %v", entry.FullPath, err) return fmt.Errorf("insert entry %s: %v", entry.FullPath, err)
} }
if err := f.store.AddDirectoryLink(lastDirectoryEntry, 1); err != nil {
return fmt.Errorf("insert entry %s: %v", entry.FullPath, err)
}
return nil return nil
} }

2
weed/filer2/filer_structure.go

@ -28,7 +28,6 @@ type Attr struct {
Uid uint32 // owner uid Uid uint32 // owner uid
Gid uint32 // group gid Gid uint32 // group gid
Size uint64 // total size in bytes Size uint64 // total size in bytes
Nlink uint32 // number of links (usually 1)
} }
type Entry struct { type Entry struct {
@ -60,7 +59,6 @@ var ErrNotFound = errors.New("filer: no entry is found in filer store")
type FilerStore interface { type FilerStore interface {
InsertEntry(*Entry) (error) InsertEntry(*Entry) (error)
AddDirectoryLink(directory *Entry, delta int32) (err error)
AppendFileChunk(FullPath, FileChunk) (err error) AppendFileChunk(FullPath, FileChunk) (err error)
FindEntry(FullPath) (found bool, entry *Entry, err error) FindEntry(FullPath) (found bool, entry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error) DeleteEntry(FullPath) (fileEntry *Entry, err error)

5
weed/filer2/memdb/memdb_store.go

@ -31,11 +31,6 @@ func (filer *MemDbStore) InsertEntry(entry *filer2.Entry) (err error) {
return nil return nil
} }
func (filer *MemDbStore) AddDirectoryLink(directory *filer2.Entry, delta int32) (err error) {
directory.Nlink = uint32(int32(directory.Nlink) + delta)
return nil
}
func (filer *MemDbStore) AppendFileChunk(fullpath filer2.FullPath, fileChunk filer2.FileChunk) (err error) { func (filer *MemDbStore) AppendFileChunk(fullpath filer2.FullPath, fileChunk filer2.FileChunk) (err error) {
found, entry, err := filer.FindEntry(fullpath) found, entry, err := filer.FindEntry(fullpath)
if !found { if !found {

11
weed/filer2/memdb/memdb_store_test.go

@ -101,8 +101,9 @@ func TestCreateFileAndList(t *testing.T) {
return return
} }
file3Path := filer2.FullPath("/home/chris/this/is/file3.jpg")
entry3 := &filer2.Entry{ entry3 := &filer2.Entry{
FullPath: filer2.FullPath("/home/chris/this/is/file3.jpg"),
FullPath: file3Path,
Attr: filer2.Attr{ Attr: filer2.Attr{
Mode: 0440, Mode: 0440,
Uid: 1234, Uid: 1234,
@ -118,4 +119,12 @@ func TestCreateFileAndList(t *testing.T) {
return return
} }
// delete file and count
filer.DeleteEntry(file3Path)
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"))
if len(entries) != 1 {
t.Errorf("list entries count: %v", len(entries))
return
}
} }
Loading…
Cancel
Save