File tree 4 files changed +31
-0
lines changed
testdata/loops/regular_4_with_permission_error
4 files changed +31
-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,7 +31,9 @@ package paths
31
31
32
32
import (
33
33
"fmt"
34
+ "io/fs"
34
35
"os"
36
+ "runtime"
35
37
"testing"
36
38
"time"
37
39
@@ -317,4 +319,25 @@ func TestReadDirRecursiveLoopDetection(t *testing.T) {
317
319
pathEqualsTo (t , "testdata/loops/regular_3/dir2/file2" , l [5 ])
318
320
pathEqualsTo (t , "testdata/loops/regular_3/link" , l [6 ]) // broken symlink is reported in files
319
321
}
322
+
323
+ if runtime .GOOS != "windows" {
324
+ dir1 := loopsPath .Join ("regular_4_with_permission_error" , "dir1" )
325
+
326
+ l , err := unbuondedReaddir ("regular_4_with_permission_error" )
327
+ require .NoError (t , err )
328
+ require .NotEmpty (t , l )
329
+
330
+ dir1Stat , err := dir1 .Stat ()
331
+ require .NoError (t , err )
332
+ err = dir1 .Chmod (fs .FileMode (0 )) // Enforce permission error
333
+ require .NoError (t , err )
334
+ t .Cleanup (func () {
335
+ // Restore normal permission after the test
336
+ dir1 .Chmod (dir1Stat .Mode ())
337
+ })
338
+
339
+ l , err = unbuondedReaddir ("regular_4_with_permission_error" )
340
+ require .Error (t , err )
341
+ require .Nil (t , l )
342
+ }
320
343
}
Original file line number Diff line number Diff line change
1
+ broken
You can’t perform that action at this time.
0 commit comments