Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kullias/wfs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: xbsoftware/wfs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Aug 26, 2020

  1. Copy the full SHA
    5710d5a View commit details

Commits on Jan 15, 2025

  1. [update] file filtering

    epoddubskij committed Jan 15, 2025
    Copy the full SHA
    6986c13 View commit details

Commits on Jan 16, 2025

  1. Merge pull request xbsoftware#4 from epoddubskij/update-filtering

    [update] file filtering
    mkozhukh authored Jan 16, 2025
    Copy the full SHA
    a62956c View commit details
Showing with 34 additions and 30 deletions.
  1. +24 −21 drive.go
  2. +2 −1 filetype.go
  3. +8 −8 types.go
45 changes: 24 additions & 21 deletions drive.go
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ type DriveFacade struct {
operation *OperationConfig
verbose bool

policy Policy
policy Policy
}


// NewLocalDrive returns new LocalDrive object
// which represents the file folder on local drive
// due to ForceRootPolicy all operations outside of the root folder will be blocked
func NewDrive(adapter Adapter, config *DriveConfig) Drive {
drive := DriveFacade{adapter:adapter, policy:adapter }
drive := DriveFacade{adapter: adapter, policy: adapter}

if config != nil {
drive.verbose = config.Verbose
@@ -51,7 +50,6 @@ func NewDrive(adapter Adapter, config *DriveConfig) Drive {
return &drive
}


// allow method checks is operation on object allowed or not
func (d *DriveFacade) allow(id FileID, operation int) bool {
return d.policy.Comply(id, operation)
@@ -130,7 +128,6 @@ func (d *DriveFacade) Read(id string) (io.ReadSeeker, error) {
log.Printf("Read %s", id)
}


if !d.allow(path, ReadOperation) {
return nil, errors.New("Access Denied")
}
@@ -174,15 +171,15 @@ func (d *DriveFacade) Info(id string) (File, error) {
return File{}, errors.New("Access Denied")
}

info,err := d.adapter.Info(path)
info, err := d.adapter.Info(path)
if err != nil {
return File{}, errors.New("Access denied")
}

return File{ID: info.File().ClientID(), Name:info.Name(), Size: info.Size(), Date: info.ModTime().Unix(), Type: GetType(info.Name(), info.IsDir()), Files: nil }, nil
return File{ID: info.File().ClientID(), Name: info.Name(), Size: info.Size(), Date: info.ModTime().Unix(), Type: GetType(info.Name(), info.IsDir()), Files: nil}, nil
}

//Mkdir creates a new folder
// Mkdir creates a new folder
func (d *DriveFacade) Make(id, name string, isFolder bool) (string, error) {
if d.verbose {
log.Printf("Make folder %s", id)
@@ -230,7 +227,6 @@ func (d *DriveFacade) Copy(source, target, name string) (string, error) {
return "", errors.New("Can't copy folder into self")
}


if d.operation.PreventNameCollision {
var err error

@@ -304,31 +300,38 @@ func (d *DriveFacade) listFolder(path FileID, config *ListConfig, res []File) ([
}

for _, file := range list {
skipFile := false
if config.Exclude != nil && config.Exclude(file.Name()) {
fullID := file.File()
isDir := file.IsDir()

fs := File{
Name: file.Name(),
ID: fullID.ClientID(),
Size: file.Size(),
Date: file.ModTime().Unix(),
Type: GetType(file.Name(), isDir),
Files: nil,
}

if config.Exclude != nil && config.Exclude(fs) {
continue
}
if config.Include != nil && !config.Include(file.Name()) {

skipFile := false
if config.Include != nil && !config.Include(fs) {
skipFile = true
}

isDir := file.IsDir()
if !isDir && (config.SkipFiles || skipFile) {
continue
}

id := file.File().ClientID()
fs := File{file.Name(), id, file.Size(), file.ModTime().Unix(), GetType(file.Name(), file.IsDir()), nil}

if isDir && config.SubFolders {
sub, err := d.listFolder(file.File(),
config, res)

fs.Type = "folder"
sub, err := d.listFolder(fullID, config, res)
if err != nil {
return nil, err
}

fs.Type = "folder"
if !config.Nested {
res = sub
} else if len(sub) > 0 {
@@ -387,4 +390,4 @@ func (d *DriveFacade) WithOperationConfig(config *OperationConfig) Drive {

func (d *DriveFacade) Stats() (uint64, uint64, error) {
return d.adapter.Stats()
}
}
3 changes: 2 additions & 1 deletion filetype.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@ func init() {
"doc": "document",
"odt": "document",
"xls": "document",
"xslx": "document",
"xlsx": "document",
"ods": "document",
"pdf": "document",
"djvu": "document",
"djv": "document",
16 changes: 8 additions & 8 deletions types.go
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ import (

// File stores info about single file
type File struct {
Name string `json:"value"`
ID string `json:"id"`
Size int64 `json:"size"`
Date int64 `json:"date"`
Type string `json:"type"`
Name string `json:"value"`
ID string `json:"id"`
Size int64 `json:"size"`
Date int64 `json:"date"`
Type string `json:"type"`
Files []File `json:"data,omitempty"`
}

@@ -27,7 +27,7 @@ type Drive interface {
Make(id, name string, isFolder bool) (string, error)
Copy(source, target, name string) (string, error)
Move(source, target, name string) (string, error)
Stats() (uint64, uint64, error)
Stats() (uint64, uint64, error)
}

type FileInfo interface {
@@ -37,7 +37,7 @@ type FileInfo interface {

type Adapter interface {
// implements Policy
Comply(FileID,int) bool
Comply(FileID, int) bool

// converts client id <-> server id
ToFileID(id string) FileID
@@ -87,7 +87,7 @@ type OperationConfig struct {
}

// MatcherFunc receives path and returns true if path matches the rule
type MatcherFunc func(string) bool
type MatcherFunc func(File) bool

// Supported operation modes
const (