Skip to content

Commit f32e4cd

Browse files
committed
Add Chmod and expand a test
1 parent 99a3246 commit f32e4cd

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

Diff for: paths.go

+7
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ func (p *Path) CopyDirTo(dst *Path) error {
418418
return nil
419419
}
420420

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+
421428
// Chtimes changes the access and modification times of the named file,
422429
// similar to the Unix utime() or utimes() functions.
423430
func (p *Path) Chtimes(atime, mtime time.Time) error {

Diff for: readdir_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package paths
3131

3232
import (
3333
"fmt"
34+
"io/fs"
3435
"os"
3536
"testing"
3637
"time"
@@ -317,4 +318,25 @@ func TestReadDirRecursiveLoopDetection(t *testing.T) {
317318
pathEqualsTo(t, "testdata/loops/regular_3/dir2/file2", l[5])
318319
pathEqualsTo(t, "testdata/loops/regular_3/link", l[6]) // broken symlink is reported in files
319320
}
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+
}
320342
}

Diff for: testdata/loops/regular_4_with_permission_error/dir1/file1

Whitespace-only changes.

Diff for: testdata/loops/regular_4_with_permission_error/link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
broken

0 commit comments

Comments
 (0)