Skip to content

Commit

Permalink
Quota stubs (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
butonic authored Aug 11, 2021
1 parent 8485d40 commit ec4099d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/quota-stubs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Add quota stubs

The `owncloud` and `owncloudsql` drivers now read the available quota from disk to no longer always return 0, which causes the web UI to disable uploads.

https://github.com/cs3org/reva/pull/1985
4 changes: 0 additions & 4 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,10 +1119,6 @@ func (fs *ocfs) UpdateGrant(ctx context.Context, ref *provider.Reference, g *pro
return fs.propagate(ctx, ip)
}

func (fs *ocfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
return 0, 0, nil
}

func (fs *ocfs) CreateHome(ctx context.Context) error {
u, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
Expand Down
14 changes: 14 additions & 0 deletions pkg/storage/fs/owncloud/owncloud_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *ocfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
stat := syscall.Statfs_t{}
err := syscall.Statfs(fs.toInternalPath(ctx, "/"), &stat)
if err != nil {
return 0, 0, err
}
total := stat.Blocks * uint64(stat.Bsize) // Total data blocks in filesystem
used := (stat.Blocks - stat.Bavail) * uint64(stat.Bsize) // Free blocks available to unprivileged user
return total, used, nil
}
19 changes: 19 additions & 0 deletions pkg/storage/fs/owncloud/owncloud_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *ocfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
var free, total, avail uint64

pathPtr, err := windows.UTF16PtrFromString(fs.toInternalPath(ctx, "/"))
if err != nil {
return 0, 0, err
}
err = windows.GetDiskFreeSpaceEx(pathPtr, &avail, &total, &free)
if err != nil {
return 0, 0, err
}

used := total - free
return total, used, nil
}
4 changes: 0 additions & 4 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,6 @@ func (fs *owncloudsqlfs) UpdateGrant(ctx context.Context, ref *provider.Referenc
return nil // nop
}

func (fs *owncloudsqlfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
return 0, 0, nil
}

func (fs *owncloudsqlfs) CreateHome(ctx context.Context) error {
u, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
Expand Down
14 changes: 14 additions & 0 deletions pkg/storage/fs/owncloudsql/owncloudsql_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
etag := fmt.Sprintf("%x", h.Sum(nil))
return strings.Trim(etag, "\"")
}

func (fs *owncloudsqlfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
stat := syscall.Statfs_t{}
err := syscall.Statfs(fs.toInternalPath(ctx, "/"), &stat)
if err != nil {
return 0, 0, err
}
total := stat.Blocks * uint64(stat.Bsize) // Total data blocks in filesystem
used := (stat.Blocks - stat.Bavail) * uint64(stat.Bsize) // Free blocks available to unprivileged user
return total, used, nil
}
19 changes: 19 additions & 0 deletions pkg/storage/fs/owncloudsql/owncloudsql_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ func calcEtag(ctx context.Context, fi os.FileInfo) string {
etag := fmt.Sprintf(`"%x"`, h.Sum(nil))
return fmt.Sprintf("\"%s\"", strings.Trim(etag, "\""))
}

func (fs *owncloudsqlfs) GetQuota(ctx context.Context) (uint64, uint64, error) {
// TODO quota of which storage space?
// we could use the logged in user, but when a user has access to multiple storages this falls short
// for now return quota of root
var free, total, avail uint64

pathPtr, err := windows.UTF16PtrFromString(fs.toInternalPath(ctx, "/"))
if err != nil {
return 0, 0, err
}
err = windows.GetDiskFreeSpaceEx(pathPtr, &avail, &total, &free)
if err != nil {
return 0, 0, err
}

used := total - free
return total, used, nil
}

0 comments on commit ec4099d

Please sign in to comment.