本文整理汇总了Golang中syscall.Dir.Null方法的典型用法代码示例。如果您正苦于以下问题:Golang Dir.Null方法的具体用法?Golang Dir.Null怎么用?Golang Dir.Null使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.Dir
的用法示例。
在下文中一共展示了Dir.Null方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rename
func rename(oldname, newname string) error {
dirname := oldname[:lastIndex(oldname, '/')+1]
if hasPrefix(newname, dirname) {
newname = newname[len(dirname):]
} else {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
// If newname still contains slashes after removing the oldname
// prefix, the rename is cross-directory and must be rejected.
// This case is caught by d.Marshal below.
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &LinkError{"rename", oldname, newname, err}
}
return nil
}
示例2: Rename
// Rename renames a file.
func Rename(oldname, newname string) error {
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"rename", oldname, err}
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &PathError{"rename", oldname, err}
}
return nil
}
示例3: Truncate
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
var d syscall.Dir
d.Null()
d.Length = size
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"truncate", name, err}
}
if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"truncate", name, err}
}
return nil
}
示例4: Chtimes
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
// The underlying filesystem may truncate or round the values to a
// less precise time unit.
// If there is an error, it will be of type *PathError.
func Chtimes(name string, atime time.Time, mtime time.Time) error {
var d syscall.Dir
d.Null()
d.Atime = uint32(atime.Unix())
d.Mtime = uint32(mtime.Unix())
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"chtimes", name, err}
}
if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"chtimes", name, err}
}
return nil
}
示例5: Sync
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func (f *File) Sync() (err error) {
if f == nil {
return ErrInvalid
}
var d syscall.Dir
d.Null()
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return NewSyscallError("fsync", err)
}
if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
return NewSyscallError("fsync", err)
}
return nil
}
示例6: Chmod
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
// If there is an error, it will be of type *PathError.
func Chmod(name string, mode FileMode) error {
var d syscall.Dir
odir, e := dirstat(name)
if e != nil {
return &PathError{"chmod", name, e}
}
d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"chmod", name, err}
}
if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"chmod", name, err}
}
return nil
}
示例7: rename
func rename(oldname, newname string) error {
dirname := oldname[:lastIndex(oldname, '/')+1]
if hasPrefix(newname, dirname) {
newname = newname[len(dirname):]
} else {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
// If newname still contains slashes after removing the oldname
// prefix, the rename is cross-directory and must be rejected.
if lastIndex(newname, '/') >= 0 {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
// If newname already exists and is not a directory, rename replaces it.
f, err := Stat(dirname + newname)
if err == nil && !f.IsDir() {
Remove(dirname + newname)
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &LinkError{"rename", oldname, newname, err}
}
return nil
}