Debian Codegraph @

osfs/os_plan9.go

raw symbols SCIP
1 //go:build plan9
2
3 package osfs
4
5 import (
6 "io"
7 "os"
8 "path/filepath"
9 "syscall"
10 )
11
12 func (f *file) Sync() error {
13 return f.File.Sync()
14 }
15
16 func rename(from, to string) error {
17 // If from and to are in different directories, copy the file
18 // since Plan 9 does not support cross-directory rename.
19 if filepath.Dir(from) != filepath.Dir(to) {
20 fi, err := os.Stat(from)
21 if err != nil {
22 return &os.LinkError{"rename", from, to, err}
23 }
24 if fi.Mode().IsDir() {
25 return &os.LinkError{"rename", from, to, syscall.EISDIR}
26 }
27 fromFile, err := os.Open(from)
28 if err != nil {
29 return &os.LinkError{"rename", from, to, err}
30 }
31 toFile, err := os.OpenFile(to, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fi.Mode())
32 if err != nil {
33 return &os.LinkError{"rename", from, to, err}
34 }
35 _, err = io.Copy(toFile, fromFile)
36 if err != nil {
37 return &os.LinkError{"rename", from, to, err}
38 }
39
40 // Copy mtime and mode from original file.
41 // We need only one syscall if we avoid os.Chmod and os.Chtimes.
42 dir := fi.Sys().(*syscall.Dir)
43 var d syscall.Dir
44 d.Null()
45 d.Mtime = dir.Mtime
46 d.Mode = dir.Mode
47 if err = dirwstat(to, &d); err != nil {
48 return &os.LinkError{"rename", from, to, err}
49 }
50
51 // Remove original file.
52 err = os.Remove(from)
53 if err != nil {
54 return &os.LinkError{"rename", from, to, err}
55 }
56 return nil
57 }
58 return os.Rename(from, to)
59 }
60
61 func dirwstat(name string, d *syscall.Dir) error {
62 var buf [syscall.STATFIXLEN]byte
63
64 n, err := d.Marshal(buf[:])
65 if err != nil {
66 return &os.PathError{"dirwstat", name, err}
67 }
68 if err = syscall.Wstat(name, buf[:n]); err != nil {
69 return &os.PathError{"dirwstat", name, err}
70 }
71 return nil
72 }
73
74 func umask(new int) func() {
75 return func() {
76 }
77 }