Skip to content

Commit

Permalink
Merge pull request #41 from basenana/fix/sqlitewithcgo
Browse files Browse the repository at this point in the history
Use a SQLite driver that doesn't depend on cgo
  • Loading branch information
hyponet authored Apr 5, 2023
2 parents 2f9c703 + e3fcd04 commit c80a673
Show file tree
Hide file tree
Showing 1,218 changed files with 3,618,678 additions and 262,788 deletions.
2 changes: 1 addition & 1 deletion cmd/apps/fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (f *File) Write(ctx context.Context, data []byte, off int64) (written uint3

func (f *File) Flush(ctx context.Context) syscall.Errno {
defer utils.TraceRegion(ctx, "files.flush")()
return Error2FuseSysError(f.file.Fsync(ctx))
return Error2FuseSysError(f.file.Flush(ctx))
}

func (f *File) Fsync(ctx context.Context, flags uint32) syscall.Errno {
Expand Down
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/basenana/go-flow v0.0.0-20220322140457-971dcb315a41
github.com/bluele/gcache v0.0.2
github.com/glebarez/sqlite v1.7.0
github.com/google/uuid v1.3.0
github.com/hanwen/go-fuse/v2 v2.2.0
github.com/hyponet/eventbus v1.0.0
Expand All @@ -17,7 +18,9 @@ require (
require (
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/coreos/etcd v2.3.8+incompatible // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/glebarez/go-sqlite v1.20.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
Expand All @@ -30,13 +33,18 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230126093431-47fa9a501578 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.20.3 // indirect
)

require (
Expand All @@ -48,14 +56,12 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/spf13/cobra v1.6.1
github.com/ugorji/go/codec v1.2.10 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
gorm.io/driver/sqlite v1.4.4
gorm.io/gorm v1.24.6
)
26 changes: 18 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -55,6 +57,10 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/glebarez/go-sqlite v1.20.3 h1:89BkqGOXR9oRmG58ZrzgoY/Fhy5x0M+/WV48U5zVrZ4=
github.com/glebarez/go-sqlite v1.20.3/go.mod h1:u3N6D/wftiAzIOJtZl6BmedqxmmkDfH3q+ihjqxC9u0=
github.com/glebarez/sqlite v1.7.0 h1:A7Xj/KN2Lvie4Z4rrgQHY8MsbebX3NyWsL3n2i82MVI=
github.com/glebarez/sqlite v1.7.0/go.mod h1:PkeevrRlF/1BhQBCnzcMWzgrIk7IOop+qS2jUYLfHhk=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
Expand Down Expand Up @@ -110,7 +116,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -126,7 +132,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down Expand Up @@ -161,9 +166,6 @@ github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1h
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
Expand Down Expand Up @@ -211,6 +213,9 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230126093431-47fa9a501578 h1:VstopitMQi3hZP0fzvnsLmzXZdQGc4bEcgu24cp+d4M=
github.com/remyoudompheng/bigfft v0.0.0-20230126093431-47fa9a501578/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
Expand Down Expand Up @@ -413,12 +418,17 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.4.4 h1:gIufGoR0dQzjkyqDyYSCvsYR6fba1Gw5YKDqKeChxFc=
gorm.io/driver/sqlite v1.4.4/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.24.6 h1:wy98aq9oFEetsc4CAbKD2SoBCdMzsbSIvSUUFJuHi5s=
gorm.io/gorm v1.24.6/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
modernc.org/libc v1.22.2 h1:4U7v51GyhlWqQmwCHj28Rdq2Yzwk55ovjFrdPjs8Hb0=
modernc.org/libc v1.22.2/go.mod h1:uvQavJ1pZ0hIoC/jfqNoMLURIMhKzINIWypNM17puug=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/sqlite v1.20.3 h1:SqGJMMxjj1PHusLxdYxeQSodg7Jxn9WWkaAQjKrntZs=
modernc.org/sqlite v1.20.3/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
37 changes: 33 additions & 4 deletions pkg/dentry/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ import (
"github.com/basenana/nanafs/pkg/bio"
"github.com/basenana/nanafs/pkg/storage"
"github.com/basenana/nanafs/pkg/types"
"go.uber.org/zap"
"sync"
)

var (
fileEntryLogger *zap.SugaredLogger
)

type File interface {
Entry

GetAttr() Attr
WriteAt(ctx context.Context, data []byte, off int64) (int64, error)
ReadAt(ctx context.Context, dest []byte, off int64) (int64, error)
Fsync(ctx context.Context) error
Flush(ctx context.Context) error
Close(ctx context.Context) (err error)
}

Expand All @@ -55,21 +61,44 @@ func (f *file) WriteAt(ctx context.Context, data []byte, off int64) (int64, erro
if !f.attr.Write || f.writer == nil {
return 0, types.ErrUnsupported
}
return f.writer.WriteAt(ctx, data, off)
n, err := f.writer.WriteAt(ctx, data, off)
if err != nil {
fileEntryLogger.Errorw("write file error", "entry", f.Entry.Metadata().ID, "off", off, "err", err)
}
return n, err
}

func (f *file) Flush(ctx context.Context) error {
if !f.attr.Write {
return nil
}
err := f.writer.Flush(ctx)
if err != nil {
fileEntryLogger.Errorw("flush file error", "entry", f.Entry.Metadata().ID, "err", err)
}
return err
}

func (f *file) Fsync(ctx context.Context) error {
if !f.attr.Write {
return types.ErrUnsupported
return nil
}
return f.writer.Fsync(ctx)
err := f.writer.Flush(ctx)
if err != nil {
fileEntryLogger.Errorw("fsync file error", "entry", f.Entry.Metadata().ID, "err", err)
}
return err
}

func (f *file) ReadAt(ctx context.Context, dest []byte, off int64) (int64, error) {
if !f.attr.Read || f.reader == nil {
return 0, types.ErrUnsupported
}
return f.reader.ReadAt(ctx, dest, off)
n, err := f.reader.ReadAt(ctx, dest, off)
if err != nil {
fileEntryLogger.Errorw("read file error", "entry", f.Entry.Metadata().ID, "off", off, "err", err)
}
return n, err
}

func (f *file) Close(ctx context.Context) (err error) {
Expand Down
10 changes: 4 additions & 6 deletions pkg/dentry/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package dentry

import (
"context"
"fmt"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -57,6 +58,7 @@ func NewManager(store storage.ObjectStore, cfg config.Config) (Manager, error) {
logger: logger.NewLogger("entryManager"),
}
newLifecycle(mgr).initHooks()
fileEntryLogger = mgr.logger.Named("files")
return mgr, nil
}

Expand Down Expand Up @@ -171,12 +173,8 @@ func (m *manager) MirrorEntry(ctx context.Context, src, dstParent Entry, attr En
}

if src.IsMirror() {
srcObj, err = m.store.GetObject(ctx, srcObj.RefID)
if err != nil {
m.logger.Errorw("query source object error", "entry", src.Object().ID, "srcObj", src.Object().RefID, "err", err.Error())
return nil, err
}
m.logger.Infow("replace source object", "entry", srcObj.ID)
m.logger.Warnw("source entry is mirrored", "entry", srcObj.RefID)
return nil, fmt.Errorf("source entry is mirrored")
}

obj, err := initMirrorEntryObject(srcObj, parentObj, attr)
Expand Down
82 changes: 54 additions & 28 deletions pkg/dentry/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ var _ = Describe("TestEntryManage", func() {

var _ = Describe("TestMirrorEntryManage", func() {
var (
grp1 Entry
fileEntry Entry
mirroredFileEntry Entry
grp1 Entry
sourceFile = "test_mirror_grp1_file1"
mirrorFile2 = "test_mirror_grp1_file2"
mirrorFile3 = "test_mirror_grp1_file3"
)
Context("create group entry test_mirror_grp1", func() {
It("should be succeed", func() {
Context("create group mirror entry mirror_grp1", func() {
It("create should be succeed", func() {
var err error
grp1, err = entryManager.CreateEntry(context.TODO(), root, EntryAttr{
Name: "test_mirror_grp1",
Expand All @@ -140,8 +141,6 @@ var _ = Describe("TestMirrorEntryManage", func() {
_, err = root.Group().FindEntry(context.TODO(), "test_mirror_grp1")
Expect(err).Should(BeNil())
})
})
Context("create group mirror entry mirror_grp1", func() {
It("should be file", func() {
_, err := entryManager.MirrorEntry(context.TODO(), grp1, root, EntryAttr{
Name: "mirror_grp1",
Expand All @@ -154,65 +153,77 @@ var _ = Describe("TestMirrorEntryManage", func() {
Context("create file entry in test_mirror_grp1", func() {
It("create should be succeed", func() {
var err error
fileEntry, err = entryManager.CreateEntry(context.TODO(), grp1, EntryAttr{
Name: "test_mirror_grp1_file1",
_, err = entryManager.CreateEntry(context.TODO(), grp1, EntryAttr{
Name: sourceFile,
Kind: types.RawKind,
Access: accessPermissions,
})
Expect(err).Should(BeNil())

_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file1")
Expect(err).Should(BeNil())
})
It("mirror file should be succeed", func() {
var err error
mirroredFileEntry, err = entryManager.MirrorEntry(context.TODO(), fileEntry, grp1, EntryAttr{
Name: "test_mirror_grp1_file2",
sFile, err := grp1.Group().FindEntry(context.TODO(), sourceFile)
Expect(err).Should(BeNil())

mFile2, err := entryManager.MirrorEntry(context.TODO(), mustGetSourceEntry(sFile), grp1, EntryAttr{
Name: mirrorFile2,
Kind: types.RawKind,
Access: accessPermissions,
})
Expect(err).Should(BeNil())
Expect(mustGetSourceEntry(mFile2).Metadata().RefCount).Should(Equal(2))

_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file1")
Expect(err).Should(BeNil())
_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file2")
sFile, err = grp1.Group().FindEntry(context.TODO(), sourceFile)
Expect(err).Should(BeNil())
Expect(mustGetSourceEntry(sFile).Metadata().RefCount).Should(Equal(2))
})
It("mirror mirrored file should be succeed", func() {
_, err := entryManager.MirrorEntry(context.TODO(), mirroredFileEntry, grp1, EntryAttr{
Name: "test_mirror_grp1_file3",
mFile2, err := grp1.Group().FindEntry(context.TODO(), mirrorFile2)
Expect(err).Should(BeNil())
_, err = entryManager.MirrorEntry(context.TODO(), mustGetSourceEntry(mFile2), grp1, EntryAttr{
Name: mirrorFile3,
Kind: types.RawKind,
Access: accessPermissions,
})
Expect(err).Should(BeNil())

mirroredFile, err := grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file3")
sFile, err := grp1.Group().FindEntry(context.TODO(), sourceFile)
Expect(err).Should(BeNil())

Expect(mirroredFile.Metadata().RefID).Should(Equal(fileEntry.Metadata().ID))
Expect(mustGetSourceEntry(sFile).Metadata().RefCount).Should(Equal(3))
})
It("delete file should be succeed", func() {
_, err := entryManager.DestroyEntry(context.TODO(), grp1, fileEntry)
sFile, err := grp1.Group().FindEntry(context.TODO(), sourceFile)
Expect(err).Should(BeNil())

_, err = entryManager.DestroyEntry(context.TODO(), grp1, sFile)
Expect(err).Should(BeNil())

_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file1")
_, err = grp1.Group().FindEntry(context.TODO(), sourceFile)
Expect(err).Should(Equal(types.ErrNotFound))
f2, err := grp1.Group().FindEntry(context.TODO(), mirrorFile2)
Expect(err).Should(BeNil())
Expect(mustGetSourceEntry(f2).Metadata().RefCount).Should(Equal(2))
})
It("delete mirror file should be succeed", func() {
_, err := entryManager.DestroyEntry(context.TODO(), grp1, mirroredFileEntry)
mFile2, err := grp1.Group().FindEntry(context.TODO(), mirrorFile2)
Expect(err).Should(BeNil())
_, err = entryManager.DestroyEntry(context.TODO(), grp1, mFile2)
Expect(err).Should(BeNil())

_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file2")
_, err = grp1.Group().FindEntry(context.TODO(), mirrorFile2)
Expect(err).Should(Equal(types.ErrNotFound))
mFile3, err := grp1.Group().FindEntry(context.TODO(), mirrorFile3)
Expect(err).Should(BeNil())
Expect(mustGetSourceEntry(mFile3).Metadata().RefCount).Should(Equal(1))
})
It("delete mirror file should be succeed", func() {
mirroredFile, err := grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file3")
mirroredFile, err := grp1.Group().FindEntry(context.TODO(), mirrorFile3)
Expect(err).Should(BeNil())

_, err = entryManager.DestroyEntry(context.TODO(), grp1, mirroredFile)
Expect(err).Should(BeNil())

_, err = grp1.Group().FindEntry(context.TODO(), "test_mirror_grp1_file3")
_, err = grp1.Group().FindEntry(context.TODO(), mirrorFile3)
Expect(err).Should(Equal(types.ErrNotFound))
})
})
Expand Down Expand Up @@ -281,6 +292,21 @@ var _ = Describe("TestChangeEntryParent", func() {
})
})

func mustGetSourceEntry(en Entry) Entry {
var (
md = en.Metadata()
err error
)
for md.RefID != 0 && md.RefID != md.ID {
en, err = entryManager.GetEntry(context.TODO(), md.RefID)
if err != nil {
panic(err)
}
md = en.Metadata()
}
return en
}

var accessPermissions = types.Access{
Permissions: []types.Permission{
types.PermOwnerRead,
Expand Down
Loading

0 comments on commit c80a673

Please sign in to comment.