-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dynamic exclusions and smb automount
- Loading branch information
Son Roy Almerol
committed
Oct 31, 2024
1 parent
7a47e00
commit 0205860
Showing
4 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package utils | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/charlievieth/fastwalk" | ||
) | ||
|
||
func GetExclusions(root string) ([]string, error) { | ||
var excludedPaths []string | ||
storeMutex := new(sync.Mutex) | ||
|
||
conf := fastwalk.Config{ | ||
Follow: false, | ||
} | ||
|
||
walkFn := func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
var skipDir bool | ||
if pathErr, ok := err.(*os.PathError); ok { | ||
if errno, ok := pathErr.Err.(syscall.Errno); ok && errno == syscall.ENOTSUP { | ||
storeMutex.Lock() | ||
excludedPaths = append(excludedPaths, convertToGlobPattern(path, root)) | ||
storeMutex.Unlock() | ||
skipDir = true | ||
} | ||
} else { | ||
storeMutex.Lock() | ||
excludedPaths = append(excludedPaths, convertToGlobPattern(path, root)) | ||
storeMutex.Unlock() | ||
} | ||
if skipDir { | ||
return filepath.SkipDir | ||
} | ||
return nil | ||
} | ||
return nil | ||
} | ||
|
||
err := fastwalk.Walk(&conf, root, walkFn) | ||
|
||
return excludedPaths, err | ||
} | ||
|
||
func convertToGlobPattern(path, root string) string { | ||
relPath, _ := filepath.Rel(root, path) | ||
if d := filepath.Dir(relPath); d == "." { | ||
return "*" + filepath.Base(relPath) | ||
} | ||
return relPath + (string(os.PathSeparator) + "*") | ||
} |