Skip to content

Instantly share code, notes, and snippets.

@taichi
Created February 7, 2014 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/8859356 to your computer and use it in GitHub Desktop.
Save taichi/8859356 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
)
func main() {
fmt.Println("way")
path := "foge/moge/rel.txt"
if err := os.MkdirAll(filepath.Dir(path), 0644); err != nil {
panic(err)
}
if err := ioutil.WriteFile(path, []byte("aaa"), 0644); err != nil {
panic(err)
}
stat(path)
if err := syscall.Chmod(path, 0x1); err != nil {
panic(err)
}
if file, err := os.Open(path); err != nil {
panic(err)
} else {
fmt.Println(file.Name())
file.Close()
}
stat(path)
fmt.Println("ddd")
filepath.Walk("foge",
func(path string, info os.FileInfo, err error) error {
fmt.Println(path, info, err)
return nil
})
fmt.Println("zzz")
if err := os.RemoveAll("foge"); err != nil {
if v, ok := err.(*os.PathError); ok {
fmt.Println(v.Path)
}
fmt.Println(err.Error())
}
if err := syscall.Chmod(path, syscall.S_IWRITE); err != nil {
panic(err)
}
fmt.Println("####")
}
func stat(path string) {
if info, err := os.Lstat(path); err != nil {
panic(err)
} else {
fmt.Println(info.Mode())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment