Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quota stubs #1985

Merged
merged 3 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 := user.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 := user.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
}