github.com/cs3org/reva/v2@v2.27.7/pkg/storage/fs/local/local.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package local 20 21 import ( 22 "github.com/cs3org/reva/v2/pkg/events" 23 "github.com/cs3org/reva/v2/pkg/storage" 24 "github.com/cs3org/reva/v2/pkg/storage/fs/registry" 25 "github.com/cs3org/reva/v2/pkg/storage/utils/localfs" 26 "github.com/mitchellh/mapstructure" 27 "github.com/pkg/errors" 28 "github.com/rs/zerolog" 29 ) 30 31 func init() { 32 registry.Register("local", New) 33 } 34 35 type config struct { 36 Root string `mapstructure:"root" docs:"/var/tmp/reva/;Path of root directory for user storage."` 37 ShareFolder string `mapstructure:"share_folder" docs:"/MyShares;Path for storing share references."` 38 UserLayout string `mapstructure:"user_layout" docs:"{{.Username}};Template used for building the user's root path."` 39 DisableHome bool `mapstructure:"disable_home" docs:"false;Enable/disable special /home handling."` 40 } 41 42 func parseConfig(m map[string]interface{}) (*config, error) { 43 c := &config{} 44 if err := mapstructure.Decode(m, c); err != nil { 45 err = errors.Wrap(err, "error decoding conf") 46 return nil, err 47 } 48 return c, nil 49 } 50 51 // New returns an implementation to of the storage.FS interface that talks to 52 // a local filesystem with user homes disabled. 53 func New(m map[string]interface{}, _ events.Stream, _ *zerolog.Logger) (storage.FS, error) { 54 c, err := parseConfig(m) 55 if err != nil { 56 return nil, err 57 } 58 59 conf := localfs.Config{ 60 Root: c.Root, 61 ShareFolder: c.ShareFolder, 62 UserLayout: c.UserLayout, 63 DisableHome: c.DisableHome, 64 } 65 return localfs.NewLocalFS(&conf) 66 }