@@ -84,12 +84,13 @@ type (
84
84
)
85
85
86
86
var (
87
- ErrFlag = errors .New ("directories to scan must be listed after any option flags" )
88
- ErrIsFile = errors .New ("directory is a file" )
89
- ErrMissing = errors .New ("directory cannot be found" )
90
- ErrPath = errors .New ("directory path cannot be found or points to a file" )
91
- ErrPerm = errors .New ("directory access is blocked due to its permissions" )
92
- ErrValid = errors .New ("the operating system reports this directory is invalid" )
87
+ ErrFlag = errors .New ("this option is used after a directory, it must be placed before any directories are listed" )
88
+ ErrDirExist = errors .New ("directory does not exist" )
89
+ ErrIsFile = errors .New ("directory is a file" )
90
+ ErrMissing = errors .New ("directory cannot be found" )
91
+ ErrPath = errors .New ("directory path cannot be found or points to a file" )
92
+ ErrPerm = errors .New ("directory access is blocked due to its permissions" )
93
+ ErrValid = errors .New ("the operating system reports this directory is invalid" )
93
94
)
94
95
95
96
// Read the named zip file and return the zip comment.
@@ -142,7 +143,11 @@ func (c *Config) WalkDir(root string) error { // nolint: cyclop,funlen,gocognit
142
143
err := filepath .WalkDir (root , func (path string , d fs.DirEntry , err error ) error {
143
144
if err != nil {
144
145
if errors .Is (err , fs .ErrPermission ) {
145
- return nil
146
+ // skip permission errors for subdirectories
147
+ // but return an error if the root is inaccessible
148
+ if root != path {
149
+ return nil
150
+ }
146
151
}
147
152
return err
148
153
}
@@ -156,7 +161,8 @@ func (c *Config) WalkDir(root string) error { // nolint: cyclop,funlen,gocognit
156
161
}
157
162
c .Zips ++
158
163
if ! c .test && ! c .Print && ! c .Quiet {
159
- fmt .Print ("\r " , color .Secondary .Sprint ("Scanned " ), color .Primary .Sprintf ("%d zip archives" , c .Zips ))
164
+ fmt .Print ("\r " , color .Secondary .Sprint ("Scanned " ),
165
+ color .Primary .Sprintf ("%d zip archives" , c .Zips ))
160
166
}
161
167
// read zip file comment
162
168
cmmt , err := Read (path , c .Raw )
@@ -200,7 +206,8 @@ func (c *Config) WalkDir(root string) error { // nolint: cyclop,funlen,gocognit
200
206
dat .name = c .exports .Unique (path , c .SaveName )
201
207
c .names += len (dat .name )
202
208
if c .save (dat ) {
203
- c .WriteLog (fmt .Sprintf ("SAVED: %s (%s) << %s" , dat .name , humanize .Bytes (uint64 (len (cmmt ))), path ))
209
+ c .WriteLog (fmt .Sprintf ("SAVED: %s (%s) << %s" ,
210
+ dat .name , humanize .Bytes (uint64 (len (cmmt ))), path ))
204
211
c .saved ++
205
212
}
206
213
}
@@ -213,8 +220,18 @@ func walkErrs(root string, err error) error {
213
220
var pathError * os.PathError
214
221
if errors .As (err , & pathError ) {
215
222
if root != "" && root [:1 ] == "-" {
216
- return fmt .Errorf ("detected an options flag, %w: %s" , ErrFlag , root )
223
+ return fmt .Errorf ("%w: %s" , ErrFlag , root )
224
+ }
225
+ }
226
+ if errors .Is (err , os .ErrNotExist ) {
227
+ return fmt .Errorf ("%w: %s" , ErrDirExist , root )
228
+ }
229
+ if errors .Is (err , fs .ErrPermission ) {
230
+ f , err := os .Stat (root )
231
+ if err != nil {
232
+ return fmt .Errorf ("%w: %s" , ErrPerm , root )
217
233
}
234
+ return fmt .Errorf ("%w: %s, %s" , ErrPerm , f .Mode (), root )
218
235
}
219
236
if err != nil {
220
237
return fmt .Errorf ("walk directory: %s, %w %T" , root , err , err )
0 commit comments