File tree 4 files changed +30
-0
lines changed
testdata/loops/regular_4_with_permission_error
4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -418,6 +418,13 @@ func (p *Path) CopyDirTo(dst *Path) error {
418
418
return nil
419
419
}
420
420
421
+ // Chmod changes the mode of the named file to mode. If the file is a
422
+ // symbolic link, it changes the mode of the link's target. If there
423
+ // is an error, it will be of type *os.PathError.
424
+ func (p * Path ) Chmod (mode fs.FileMode ) error {
425
+ return os .Chmod (p .path , mode )
426
+ }
427
+
421
428
// Chtimes changes the access and modification times of the named file,
422
429
// similar to the Unix utime() or utimes() functions.
423
430
func (p * Path ) Chtimes (atime , mtime time.Time ) error {
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ package paths
31
31
32
32
import (
33
33
"fmt"
34
+ "io/fs"
34
35
"os"
35
36
"testing"
36
37
"time"
@@ -317,4 +318,25 @@ func TestReadDirRecursiveLoopDetection(t *testing.T) {
317
318
pathEqualsTo (t , "testdata/loops/regular_3/dir2/file2" , l [5 ])
318
319
pathEqualsTo (t , "testdata/loops/regular_3/link" , l [6 ]) // broken symlink is reported in files
319
320
}
321
+
322
+ {
323
+ dir1 := loopsPath .Join ("regular_4_with_permission_error" , "dir1" )
324
+
325
+ l , err := unbuondedReaddir ("regular_4_with_permission_error" )
326
+ require .NoError (t , err )
327
+ require .NotEmpty (t , l )
328
+
329
+ dir1Stat , err := dir1 .Stat ()
330
+ require .NoError (t , err )
331
+ err = dir1 .Chmod (fs .FileMode (0 )) // Enforce permission error
332
+ require .NoError (t , err )
333
+ t .Cleanup (func () {
334
+ // Restore normal permission after the test
335
+ dir1 .Chmod (dir1Stat .Mode ())
336
+ })
337
+
338
+ l , err = unbuondedReaddir ("regular_4_with_permission_error" )
339
+ require .Error (t , err )
340
+ require .Nil (t , l )
341
+ }
320
342
}
Original file line number Diff line number Diff line change
1
+ broken
You can’t perform that action at this time.
0 commit comments