File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Expand file tree Collapse file tree 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) {
318318 return
319319}
320320
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+
321332// LinkError records an error during a link or symlink or rename system call and
322333// the paths that caused it.
323334type LinkError struct {
Original file line number Diff line number Diff line change @@ -159,3 +159,7 @@ func (f *File) Truncate(size int64) (err error) {
159159func (f * File ) chmod (mode FileMode ) error {
160160 return ErrUnsupported
161161}
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 {
166166 return nil
167167}
168168
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+
169185// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
170186// It returns the number of bytes read and any error encountered, possibly io.EOF.
171187// 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 {
146146func (f * File ) chmod (mode FileMode ) error {
147147 return ErrNotImplemented
148148}
149+
150+ func (f * File ) chdir () error {
151+ return ErrNotImplemented
152+ }
You can’t perform that action at this time.
0 commit comments