Skip to content

Commit 2d17dec

Browse files
leongrossdeadprogram
authored andcommitted
os/file: add file.Chmod
Signed-off-by: leongross <leon.gross@9elements.com>
1 parent c1b267a commit 2d17dec

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/os/file.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ func (f *File) Sync() (err error) {
307307
return
308308
}
309309

310+
// Chmod changes the mode of the file to mode. If there is an error, it will be
311+
// of type *PathError.
312+
func (f *File) Chmod(mode FileMode) (err error) {
313+
if f.handle == nil {
314+
err = ErrClosed
315+
} else {
316+
err = f.chmod(mode)
317+
}
318+
return
319+
}
320+
310321
// LinkError records an error during a link or symlink or rename system call and
311322
// the paths that caused it.
312323
type LinkError struct {

src/os/file_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ func (f *File) Truncate(size int64) (err error) {
149149

150150
return Truncate(f.name, size)
151151
}
152+
153+
func (f *File) chmod(mode FileMode) error {
154+
return ErrUnsupported
155+
}

src/os/file_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ func (f *File) Truncate(size int64) (err error) {
151151
return Truncate(f.name, size)
152152
}
153153

154+
func (f *File) chmod(mode FileMode) error {
155+
if f.handle == nil {
156+
return ErrClosed
157+
}
158+
159+
longName := fixLongPath(f.name)
160+
e := ignoringEINTR(func() error {
161+
return syscall.Chmod(longName, syscallMode(mode))
162+
})
163+
if e != nil {
164+
return &PathError{Op: "chmod", Path: f.name, Err: e}
165+
}
166+
return nil
167+
}
168+
154169
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
155170
// It returns the number of bytes read and any error encountered, possibly io.EOF.
156171
// At end of file, Pread returns 0, io.EOF.

src/os/file_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ func isWindowsNulName(name string) bool {
142142
}
143143
return true
144144
}
145+
146+
func (f *File) chmod(mode FileMode) error {
147+
return ErrNotImplemented
148+
}

0 commit comments

Comments
 (0)