Skip to content

Commit

Permalink
Add filemanager.chown
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 17, 2023
1 parent 4fbbd19 commit 256fafc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions service/filemanager/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func (m *defaultManager) CreateTemp(pattern string) (*os.File, error) {
return file, nil
}

func (m *defaultManager) Chown(path string) error {
if m.chown {
return os.Chown(path, m.userID, m.groupID)
}
return nil
}

func (m *defaultManager) Mkdir(path string, perm os.FileMode) error {
path = m.BasePath(path)
err := os.Mkdir(path, perm)
Expand Down
9 changes: 9 additions & 0 deletions service/filemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Manager interface {
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
Create(name string) (*os.File, error)
CreateTemp(pattern string) (*os.File, error)
Chown(name string) error
Mkdir(path string, perm os.FileMode) error
MkdirAll(path string, perm os.FileMode) error
Remove(path string) error
Expand Down Expand Up @@ -50,6 +51,14 @@ func CreateTemp(ctx context.Context, pattern string) (*os.File, error) {
return manager.CreateTemp(pattern)
}

func Chown(ctx context.Context, name string) error {
manager := service.FromContext[Manager](ctx)
if manager == nil {
return nil
}
return manager.Chown(name)
}

func Mkdir(ctx context.Context, path string, perm os.FileMode) error {
manager := service.FromContext[Manager](ctx)
if manager == nil {
Expand Down

0 comments on commit 256fafc

Please sign in to comment.