MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / PollFolders

Method PollFolders

pkg/unpackerr/folder.go:120–158  ·  view source on GitHub ↗

PollFolders begins the routines to watch folders for changes. if those changes include the addition of compressed files, they are processed for exctraction.

()

Source from the content-addressed store, hash-verified

118// if those changes include the addition of compressed files, they
119// are processed for exctraction.
120func (u *Unpackerr) PollFolders() {
121 var (
122 flist []string
123 err error
124 )
125
126 if isRunningInDocker() && u.Folder.Interval.Duration == 0 {
127 u.Folder.Interval.Duration = defaultPollInterval
128 }
129
130 u.Folders, flist = checkFolders(u.Folders, u.Logger)
131
132 u.folders, err = u.Folder.newWatcher(u.Folders, u.Logger)
133 if err != nil {
134 u.Errorf("Watching Folders: %s", err)
135 return
136 }
137 // do not close either watcher.
138
139 if len(u.Folders) == 0 {
140 return
141 }
142
143 go u.folders.watchFSNotify()
144 u.Printf("[Folder] Watching (fsnotify): %s", strings.Join(flist, ", "))
145
146 // Setting an interval of any value less than 5 milliseconds
147 // (except zero in docker) allows disabling the poller.
148 if u.Folder.Interval.Duration < minimumPollInterval {
149 return
150 }
151
152 go func() {
153 if err := u.folders.Watcher.Start(u.Folder.Interval.Duration); err != nil {
154 u.Errorf("Folder poller stopped: %v", err)
155 }
156 }()
157 u.Printf("[Folder] Polling @ %s: %s", u.Folder.Interval.String(), strings.Join(flist, ", "))
158}
159
160// checkFolders stats all configured folders and returns only "good" ones.
161func checkFolders(folders []*FolderConfig, log Logs) ([]*FolderConfig, []string) {

Callers 1

RunMethod · 0.95

Calls 7

isRunningInDockerFunction · 0.85
checkFoldersFunction · 0.85
newWatcherMethod · 0.80
watchFSNotifyMethod · 0.80
ErrorfMethod · 0.65
PrintfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected