File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,17 @@ func (f *File) Chmod(mode FileMode) (err error) {
318
318
return
319
319
}
320
320
321
+ // Chdir changes the current working directory to the file, which must be a
322
+ // directory. If there is an error, it will be of type *PathError.
323
+ func (f * File ) Chdir () (err error ) {
324
+ if f .handle == nil {
325
+ err = ErrClosed
326
+ } else {
327
+ err = f .chdir ()
328
+ }
329
+ return
330
+ }
331
+
321
332
// LinkError records an error during a link or symlink or rename system call and
322
333
// the paths that caused it.
323
334
type LinkError struct {
Original file line number Diff line number Diff line change @@ -159,3 +159,7 @@ func (f *File) Truncate(size int64) (err error) {
159
159
func (f * File ) chmod (mode FileMode ) error {
160
160
return ErrUnsupported
161
161
}
162
+
163
+ func (f * File ) chdir () error {
164
+ return ErrNotImplemented
165
+ }
Original file line number Diff line number Diff line change @@ -166,6 +166,22 @@ func (f *File) chmod(mode FileMode) error {
166
166
return nil
167
167
}
168
168
169
+ func (f * File ) chdir () error {
170
+ if f .handle == nil {
171
+ return ErrClosed
172
+ }
173
+
174
+ // TODO: use syscall.Fchdir instead
175
+ longName := fixLongPath (f .name )
176
+ e := ignoringEINTR (func () error {
177
+ return syscall .Chdir (longName )
178
+ })
179
+ if e != nil {
180
+ return & PathError {Op : "chdir" , Path : f .name , Err : e }
181
+ }
182
+ return nil
183
+ }
184
+
169
185
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
170
186
// It returns the number of bytes read and any error encountered, possibly io.EOF.
171
187
// At end of file, Pread returns 0, io.EOF.
Original file line number Diff line number Diff line change @@ -146,3 +146,7 @@ func isWindowsNulName(name string) bool {
146
146
func (f * File ) chmod (mode FileMode ) error {
147
147
return ErrNotImplemented
148
148
}
149
+
150
+ func (f * File ) chdir () error {
151
+ return ErrNotImplemented
152
+ }
You can’t perform that action at this time.
0 commit comments