This commit is contained in:
abhiguptacse 2024-10-08 15:14:39 +00:00
Родитель f3b428b548
Коммит 497a39985a
4 изменённых файлов: 49 добавлений и 49 удалений

Просмотреть файл

@ -7,7 +7,7 @@ import (
"strings" "strings"
"github.com/Azure/azure-storage-fuse/v2/common/log" "github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/external" "github.com/Azure/azure-storage-fuse/v2/exported"
"github.com/Azure/azure-storage-fuse/v2/internal" "github.com/Azure/azure-storage-fuse/v2/internal"
) )
@ -32,7 +32,7 @@ func init() {
} else { } else {
files, err := os.ReadDir(pluginDirPath) files, err := os.ReadDir(pluginDirPath)
if err != nil { if err != nil {
log.Err("custom_loader::Error reading plugin directory: %s", err.Error()) log.Err("custom::Error reading plugin directory: %s", err.Error())
return return
} }
for _, file := range files { for _, file := range files {
@ -43,22 +43,22 @@ func init() {
} }
for _, file := range pluginFiles { for _, file := range pluginFiles {
log.Info("custom_loader::Opening plugin: %s", file) log.Info("custom::Opening plugin: %s", file)
p, err := plugin.Open(file) p, err := plugin.Open(file)
if err != nil { if err != nil {
log.Err("custom_loader::Error opening plugin: %s", err.Error()) log.Err("custom::Error opening plugin: %s", err.Error())
os.Exit(1) os.Exit(1)
} }
log.Info("custom_loader::Plugin opened successfully") log.Info("custom::Plugin opened successfully")
getExternalComponentFunc, err := p.Lookup("GetExternalComponent") getExternalComponentFunc, err := p.Lookup("GetExternalComponent")
if err != nil { if err != nil {
log.Err("custom_loader::Error looking up GetExternalComponent function: %s", err.Error()) log.Err("custom::Error looking up GetExternalComponent function: %s", err.Error())
os.Exit(1) os.Exit(1)
} }
getExternalComponent, ok := getExternalComponentFunc.(func() (string, func() external.Component)) getExternalComponent, ok := getExternalComponentFunc.(func() (string, func() exported.Component))
if !ok { if !ok {
log.Err("custom_loader::Error casting GetExternalComponent function") log.Err("custom::Error casting GetExternalComponent function")
os.Exit(1) os.Exit(1)
} }
compName, initExternalComponent := getExternalComponent() compName, initExternalComponent := getExternalComponent()

Просмотреть файл

@ -1,11 +1,11 @@
package external package exported
import ( import (
"github.com/Azure/azure-storage-fuse/v2/internal" "github.com/Azure/azure-storage-fuse/v2/internal"
"github.com/Azure/azure-storage-fuse/v2/internal/handlemap" "github.com/Azure/azure-storage-fuse/v2/internal/handlemap"
) )
// Package external is a wrapper around internal package to expose the internal attributes for writing custom components. // Package exported is a wrapper around internal package to expose the internal attributes for writing custom components.
const ( const (
PropFlagUnknown uint16 = iota PropFlagUnknown uint16 = iota
PropFlagNotExists PropFlagNotExists

Просмотреть файл

@ -7,34 +7,34 @@ import (
"github.com/Azure/azure-storage-fuse/v2/common/config" "github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/log" "github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/external" "github.com/Azure/azure-storage-fuse/v2/exported"
) )
// SAMPLE EXTERNAL COMPONENT IMPLEMENTATION // SAMPLE CUSTOM COMPONENT IMPLEMENTATION
// To build this component run the following command: // To build this component run the following command:
// "go build -buildmode=plugin -o sample_custom_component1.so" // "go build -buildmode=plugin -o sample_custom_component1.so"
// This is a sample external component implementation that can be used as a reference to implement external components. // This is a sample custom component implementation that can be used as a reference to implement custom components.
// The external component should implement the external.Component interface. // The custom component should implement the exported.Component interface.
const ( const (
CompName = "sample_custom_component1" CompName = "sample_custom_component1"
Mb = 1024 * 1024 Mb = 1024 * 1024
) )
var _ external.Component = &sample_custom_component1{} var _ exported.Component = &sample_custom_component1{}
func (e *sample_custom_component1) SetName(name string) { func (e *sample_custom_component1) SetName(name string) {
e.BaseComponent.SetName(name) e.BaseComponent.SetName(name)
} }
func (e *sample_custom_component1) SetNextComponent(nc external.Component) { func (e *sample_custom_component1) SetNextComponent(nc exported.Component) {
e.BaseComponent.SetNextComponent(nc) e.BaseComponent.SetNextComponent(nc)
} }
func GetExternalComponent() (string, func() external.Component) { func GetExternalComponent() (string, func() exported.Component) {
return CompName, NewexternalComponent return CompName, NewexternalComponent
} }
func NewexternalComponent() external.Component { func NewexternalComponent() exported.Component {
comp := &sample_custom_component1{} comp := &sample_custom_component1{}
comp.SetName(CompName) comp.SetName(CompName)
return comp return comp
@ -42,7 +42,7 @@ func NewexternalComponent() external.Component {
type sample_custom_component1 struct { type sample_custom_component1 struct {
blockSize int64 blockSize int64
external.BaseComponent exported.BaseComponent
} }
type sample_custom_component1Options struct { type sample_custom_component1Options struct {
@ -63,7 +63,7 @@ func (e *sample_custom_component1) Configure(isParent bool) error {
return nil return nil
} }
func (e *sample_custom_component1) CreateFile(opt external.CreateFileOptions) (*external.Handle, error) { func (e *sample_custom_component1) CreateFile(opt exported.CreateFileOptions) (*exported.Handle, error) {
log.Trace("sample_custom_component1::CreateFile : %s", opt.Name) log.Trace("sample_custom_component1::CreateFile : %s", opt.Name)
handle, err := e.NextComponent().CreateFile(opt) handle, err := e.NextComponent().CreateFile(opt)
if err != nil { if err != nil {
@ -73,7 +73,7 @@ func (e *sample_custom_component1) CreateFile(opt external.CreateFileOptions) (*
return handle, nil return handle, nil
} }
func (e *sample_custom_component1) CreateDir(opt external.CreateDirOptions) error { func (e *sample_custom_component1) CreateDir(opt exported.CreateDirOptions) error {
log.Trace("sample_custom_component1::CreateDir : %s", opt.Name) log.Trace("sample_custom_component1::CreateDir : %s", opt.Name)
err := e.NextComponent().CreateDir(opt) err := e.NextComponent().CreateDir(opt)
if err != nil { if err != nil {
@ -83,7 +83,7 @@ func (e *sample_custom_component1) CreateDir(opt external.CreateDirOptions) erro
return nil return nil
} }
func (e *sample_custom_component1) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) { func (e *sample_custom_component1) StreamDir(options exported.StreamDirOptions) ([]*exported.ObjAttr, string, error) {
log.Trace("sample_custom_component1::StreamDir : %s", options.Name) log.Trace("sample_custom_component1::StreamDir : %s", options.Name)
attr, token, err := e.NextComponent().StreamDir(options) attr, token, err := e.NextComponent().StreamDir(options)
@ -93,13 +93,13 @@ func (e *sample_custom_component1) StreamDir(options external.StreamDirOptions)
} }
return attr, token, nil return attr, token, nil
} }
func (e *sample_custom_component1) IsDirEmpty(options external.IsDirEmptyOptions) bool { func (e *sample_custom_component1) IsDirEmpty(options exported.IsDirEmptyOptions) bool {
log.Trace("test2::IsDirEmpty : %s", options.Name) log.Trace("test2::IsDirEmpty : %s", options.Name)
empty := e.NextComponent().IsDirEmpty(options) empty := e.NextComponent().IsDirEmpty(options)
return empty return empty
} }
func (e *sample_custom_component1) DeleteDir(opt external.DeleteDirOptions) error { func (e *sample_custom_component1) DeleteDir(opt exported.DeleteDirOptions) error {
log.Trace("sample_custom_component1::DeleteDir : %s", opt.Name) log.Trace("sample_custom_component1::DeleteDir : %s", opt.Name)
err := e.NextComponent().DeleteDir(opt) err := e.NextComponent().DeleteDir(opt)
if err != nil { if err != nil {
@ -109,7 +109,7 @@ func (e *sample_custom_component1) DeleteDir(opt external.DeleteDirOptions) erro
return nil return nil
} }
func (e *sample_custom_component1) StageData(opt external.StageDataOptions) error { func (e *sample_custom_component1) StageData(opt exported.StageDataOptions) error {
log.Trace("sample_custom_component1::StageData : %s", opt.Name) log.Trace("sample_custom_component1::StageData : %s", opt.Name)
err := e.NextComponent().StageData(opt) err := e.NextComponent().StageData(opt)
if err != nil { if err != nil {
@ -119,7 +119,7 @@ func (e *sample_custom_component1) StageData(opt external.StageDataOptions) erro
return nil return nil
} }
func (e *sample_custom_component1) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) { func (e *sample_custom_component1) ReadInBuffer(opt exported.ReadInBufferOptions) (length int, err error) {
log.Trace("sample_custom_component1::ReadInBuffer : %s", opt.Handle.Path) log.Trace("sample_custom_component1::ReadInBuffer : %s", opt.Handle.Path)
n, err := e.NextComponent().ReadInBuffer(opt) n, err := e.NextComponent().ReadInBuffer(opt)
if err != nil { if err != nil {
@ -129,7 +129,7 @@ func (e *sample_custom_component1) ReadInBuffer(opt external.ReadInBufferOptions
return n, nil return n, nil
} }
func (e *sample_custom_component1) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) { func (e *sample_custom_component1) GetAttr(options exported.GetAttrOptions) (attr *exported.ObjAttr, err error) {
log.Trace("sample_custom_component1::GetAttr : %s", options.Name) log.Trace("sample_custom_component1::GetAttr : %s", options.Name)
attr, err = e.NextComponent().GetAttr(options) attr, err = e.NextComponent().GetAttr(options)
if err != nil { if err != nil {

Просмотреть файл

@ -9,35 +9,35 @@ import (
"github.com/Azure/azure-storage-fuse/v2/common/config" "github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/log" "github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/external" "github.com/Azure/azure-storage-fuse/v2/exported"
"github.com/Azure/azure-storage-fuse/v2/internal" "github.com/Azure/azure-storage-fuse/v2/internal"
) )
// SAMPLE EXTERNAL COMPONENT IMPLEMENTATION // SAMPLE CUSTOM COMPONENT IMPLEMENTATION
// To build this component run the following command: // To build this component run the following command:
// "go build -buildmode=plugin -o sample_custom_component2.so" // "go build -buildmode=plugin -o sample_custom_component2.so"
// This is a sample external component implementation that can be used as a reference to implement external components. // This is a sample custom component implementation that can be used as a reference to implement custom components.
// The external component should implement the external.Component interface. // The custom component should implement the exported.Component interface.
const ( const (
CompName = "sample_custom_component2" CompName = "sample_custom_component2"
Mb = 1024 * 1024 Mb = 1024 * 1024
) )
var _ external.Component = &sample_custom_component2{} var _ exported.Component = &sample_custom_component2{}
func (e *sample_custom_component2) SetName(name string) { func (e *sample_custom_component2) SetName(name string) {
e.BaseComponent.SetName(name) e.BaseComponent.SetName(name)
} }
func (e *sample_custom_component2) SetNextComponent(nc external.Component) { func (e *sample_custom_component2) SetNextComponent(nc exported.Component) {
e.BaseComponent.SetNextComponent(nc) e.BaseComponent.SetNextComponent(nc)
} }
func GetExternalComponent() (string, func() external.Component) { func GetExternalComponent() (string, func() exported.Component) {
return CompName, NewexternalComponent return CompName, NewexternalComponent
} }
func NewexternalComponent() external.Component { func NewexternalComponent() exported.Component {
comp := &sample_custom_component2{} comp := &sample_custom_component2{}
comp.SetName(CompName) comp.SetName(CompName)
return comp return comp
@ -46,7 +46,7 @@ func NewexternalComponent() external.Component {
type sample_custom_component2 struct { type sample_custom_component2 struct {
blockSize int64 blockSize int64
externalPath string externalPath string
external.BaseComponent exported.BaseComponent
} }
type sample_custom_component2Options struct { type sample_custom_component2Options struct {
@ -73,7 +73,7 @@ func (e *sample_custom_component2) Configure(isParent bool) error {
return nil return nil
} }
func (e *sample_custom_component2) CreateFile(options external.CreateFileOptions) (*external.Handle, error) { func (e *sample_custom_component2) CreateFile(options exported.CreateFileOptions) (*exported.Handle, error) {
log.Info("sample_custom_component2::CreateFile") log.Info("sample_custom_component2::CreateFile")
filePath := filepath.Join(e.externalPath, options.Name) filePath := filepath.Join(e.externalPath, options.Name)
fileHandle, err := os.OpenFile(filePath, os.O_CREATE, 0777) fileHandle, err := os.OpenFile(filePath, os.O_CREATE, 0777)
@ -82,13 +82,13 @@ func (e *sample_custom_component2) CreateFile(options external.CreateFileOptions
return nil, err return nil, err
} }
defer fileHandle.Close() defer fileHandle.Close()
handle := &external.Handle{ handle := &exported.Handle{
Path: options.Name, Path: options.Name,
} }
return handle, nil return handle, nil
} }
func (e *sample_custom_component2) CreateDir(options external.CreateDirOptions) error { func (e *sample_custom_component2) CreateDir(options exported.CreateDirOptions) error {
log.Info("sample_custom_component2::CreateDir") log.Info("sample_custom_component2::CreateDir")
dirPath := filepath.Join(e.externalPath, options.Name) dirPath := filepath.Join(e.externalPath, options.Name)
err := os.MkdirAll(dirPath, 0777) err := os.MkdirAll(dirPath, 0777)
@ -99,7 +99,7 @@ func (e *sample_custom_component2) CreateDir(options external.CreateDirOptions)
return nil return nil
} }
func (e *sample_custom_component2) StreamDir(options external.StreamDirOptions) ([]*external.ObjAttr, string, error) { func (e *sample_custom_component2) StreamDir(options exported.StreamDirOptions) ([]*exported.ObjAttr, string, error) {
log.Info("sample_custom_component2::StreamDir") log.Info("sample_custom_component2::StreamDir")
var objAttrs []*internal.ObjAttr var objAttrs []*internal.ObjAttr
path := formatListDirName(options.Name) path := formatListDirName(options.Name)
@ -125,7 +125,7 @@ func (e *sample_custom_component2) StreamDir(options external.StreamDirOptions)
return objAttrs, "", nil return objAttrs, "", nil
} }
func (e *sample_custom_component2) IsDirEmpty(options external.IsDirEmptyOptions) bool { func (e *sample_custom_component2) IsDirEmpty(options exported.IsDirEmptyOptions) bool {
log.Info("sample_custom_component2::IsDirEmpty") log.Info("sample_custom_component2::IsDirEmpty")
files, err := os.ReadDir(filepath.Join(e.externalPath, options.Name)) files, err := os.ReadDir(filepath.Join(e.externalPath, options.Name))
if err != nil { if err != nil {
@ -135,7 +135,7 @@ func (e *sample_custom_component2) IsDirEmpty(options external.IsDirEmptyOptions
return len(files) == 0 return len(files) == 0
} }
func (e *sample_custom_component2) DeleteDir(options external.DeleteDirOptions) error { func (e *sample_custom_component2) DeleteDir(options exported.DeleteDirOptions) error {
log.Info("sample_custom_component2::DeleteDir") log.Info("sample_custom_component2::DeleteDir")
dirPath := filepath.Join(e.externalPath, options.Name) dirPath := filepath.Join(e.externalPath, options.Name)
err := os.RemoveAll(dirPath) err := os.RemoveAll(dirPath)
@ -146,7 +146,7 @@ func (e *sample_custom_component2) DeleteDir(options external.DeleteDirOptions)
return nil return nil
} }
func (e *sample_custom_component2) StageData(opt external.StageDataOptions) error { func (e *sample_custom_component2) StageData(opt exported.StageDataOptions) error {
log.Info("sample_custom_component2:: StageData") log.Info("sample_custom_component2:: StageData")
filePath := filepath.Join(e.externalPath, opt.Name) filePath := filepath.Join(e.externalPath, opt.Name)
fileHandle, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY, 0777) fileHandle, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY, 0777)
@ -168,7 +168,7 @@ func (e *sample_custom_component2) StageData(opt external.StageDataOptions) erro
return nil return nil
} }
func (e *sample_custom_component2) ReadInBuffer(opt external.ReadInBufferOptions) (length int, err error) { func (e *sample_custom_component2) ReadInBuffer(opt exported.ReadInBufferOptions) (length int, err error) {
log.Info("sample_custom_component2:: ReadInBuffer") log.Info("sample_custom_component2:: ReadInBuffer")
filePath := filepath.Join(e.externalPath, opt.Handle.Path) filePath := filepath.Join(e.externalPath, opt.Handle.Path)
@ -187,16 +187,16 @@ func (e *sample_custom_component2) ReadInBuffer(opt external.ReadInBufferOptions
return n, nil return n, nil
} }
func (e *sample_custom_component2) GetAttr(options external.GetAttrOptions) (attr *external.ObjAttr, err error) { func (e *sample_custom_component2) GetAttr(options exported.GetAttrOptions) (attr *exported.ObjAttr, err error) {
log.Info("sample_custom_component2::GetAttr for %s", options.Name) log.Info("sample_custom_component2::GetAttr for %s", options.Name)
fileAttr, err := os.Stat(filepath.Join(e.externalPath, options.Name)) fileAttr, err := os.Stat(filepath.Join(e.externalPath, options.Name))
if err != nil { if err != nil {
log.Trace("sample_custom_component2::GetAttr : Error getting file attributes: %s", err.Error()) log.Trace("sample_custom_component2::GetAttr : Error getting file attributes: %s", err.Error())
return &external.ObjAttr{}, err return &exported.ObjAttr{}, err
} }
// Populate the ObjAttr struct with the file info. // Populate the ObjAttr struct with the file info.
attr = &external.ObjAttr{ attr = &exported.ObjAttr{
Mtime: fileAttr.ModTime(), // Modified time Mtime: fileAttr.ModTime(), // Modified time
Atime: time.Now(), // Access time (current time as approximation) Atime: time.Now(), // Access time (current time as approximation)
Ctime: fileAttr.ModTime(), // Change time (same as modified time in this case) Ctime: fileAttr.ModTime(), // Change time (same as modified time in this case)
@ -207,7 +207,7 @@ func (e *sample_custom_component2) GetAttr(options external.GetAttrOptions) (att
Size: fileAttr.Size(), // File size Size: fileAttr.Size(), // File size
} }
if fileAttr.IsDir() { if fileAttr.IsDir() {
attr.Flags.Set(external.PropFlagIsDir) attr.Flags.Set(exported.PropFlagIsDir)
} }
return attr, nil return attr, nil
} }
@ -218,7 +218,7 @@ func formatListDirName(path string) string {
if path == "/" { if path == "/" {
path = "" path = ""
} else if path != "" { } else if path != "" {
path = external.ExtendDirName(path) path = exported.ExtendDirName(path)
} }
return path return path
} }