本文整理匯總了Golang中syscall.Chmod函數的典型用法代碼示例。如果您正苦於以下問題:Golang Chmod函數的具體用法?Golang Chmod怎麽用?Golang Chmod使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Chmod函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetArtifact
func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) {
if source == "" {
return "", fmt.Errorf("Source url is empty in Artifact Getter")
}
u, err := url.Parse(source)
if err != nil {
return "", err
}
// if checksum is seperate, apply to source
if checksum != "" {
source = strings.Join([]string{source, fmt.Sprintf("checksum=%s", checksum)}, "?")
logger.Printf("[DEBUG] client.getter: Applying checksum to Artifact Source URL, new url: %s", source)
}
artifactFile := filepath.Join(destDir, path.Base(u.Path))
if err := gg.GetFile(artifactFile, source); err != nil {
return "", fmt.Errorf("Error downloading artifact: %s", err)
}
// Add execution permissions to the newly downloaded artifact
if runtime.GOOS != "windows" {
if err := syscall.Chmod(artifactFile, 0755); err != nil {
logger.Printf("[ERR] driver.raw_exec: Error making artifact executable: %s", err)
}
}
return artifactFile, nil
}
示例2: ChMod
/* ============================================================================================ */
func ChMod(filename string, mode int) bool {
err := syscall.Chmod(filename, uint32(mode))
if err == nil {
return true
}
return false
}
示例3: main
func main() {
flag.Parse()
if len(flag.Args()) < 2 {
flag.PrintDefaults()
log.Fatalf("usage: chmod mode filepath")
}
octval, err := strconv.ParseUint(flag.Args()[0], 8, 32)
if err != nil {
log.Fatalf("Unable to decode mode. Please use an octal value. arg was %s, err was %v", flag.Args()[0], err)
} else if octval > 0777 {
log.Fatalf("Invalid octal value. Value larger than 777, was %o", octval)
}
mode := uint32(octval)
var errors string
for _, arg := range flag.Args()[1:] {
if err := syscall.Chmod(arg, mode); err != nil {
errors += fmt.Sprintf("Unable to chmod, filename was %s, err was %v\n", arg, err)
}
}
if errors != "" {
log.Fatalf(errors)
}
}
示例4: writeMetadata
func (inode *SpecialInode) writeMetadata(name string) error {
if err := os.Lchown(name, int(inode.Uid), int(inode.Gid)); err != nil {
return err
}
if err := syscall.Chmod(name, uint32(inode.Mode)); err != nil {
return err
}
t := time.Unix(inode.MtimeSeconds, int64(inode.MtimeNanoSeconds))
return os.Chtimes(name, t, t)
}
示例5: Chmod
// Chmod implements pathfs.Filesystem.
func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
if fs.isFiltered(path) {
return fuse.EPERM
}
cPath, err := fs.getBackingPath(path)
if err != nil {
return fuse.ToStatus(err)
}
// os.Chmod goes through the "syscallMode" translation function that messes
// up the suid and sgid bits. So use syscall.Chmod directly.
err = syscall.Chmod(cPath, mode)
return fuse.ToStatus(err)
}
示例6: write
func (inode *DirectoryInode) write(name string) error {
if inode.make(name) != nil {
os.RemoveAll(name)
if err := inode.make(name); err != nil {
return err
}
}
if err := os.Lchown(name, int(inode.Uid), int(inode.Gid)); err != nil {
return err
}
if inode.Mode & ^modePerm != syscall.S_IFDIR {
if err := syscall.Chmod(name, uint32(inode.Mode)); err != nil {
return err
}
}
return nil
}
示例7: createTarFile
func createTarFile(path, extractDir string, hdr *tar.Header, reader *tar.Reader) error {
switch hdr.Typeflag {
case tar.TypeDir:
// Create directory unless it exists as a directory already.
// In that case we just want to merge the two
if fi, err := os.Lstat(path); !(err == nil && fi.IsDir()) {
if err := os.Mkdir(path, os.FileMode(hdr.Mode)); err != nil {
return err
}
}
case tar.TypeReg, tar.TypeRegA:
// Source is regular file
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, os.FileMode(hdr.Mode))
if err != nil {
return err
}
if _, err := io.Copy(file, reader); err != nil {
file.Close()
return err
}
file.Close()
case tar.TypeBlock, tar.TypeChar, tar.TypeFifo:
mode := uint32(hdr.Mode & 07777)
switch hdr.Typeflag {
case tar.TypeBlock:
mode |= syscall.S_IFBLK
case tar.TypeChar:
mode |= syscall.S_IFCHR
case tar.TypeFifo:
mode |= syscall.S_IFIFO
}
if err := syscall.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
return err
}
case tar.TypeLink:
if err := os.Link(filepath.Join(extractDir, hdr.Linkname), path); err != nil {
return err
}
case tar.TypeSymlink:
if err := os.Symlink(hdr.Linkname, path); err != nil {
return err
}
case tar.TypeXGlobalHeader:
utils.Debugf("PAX Global Extended Headers found and ignored")
return nil
default:
return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
}
if err := syscall.Lchown(path, hdr.Uid, hdr.Gid); err != nil {
return err
}
// There is no LChmod, so ignore mode for symlink. Also, this
// must happen after chown, as that can modify the file mode
if hdr.Typeflag != tar.TypeSymlink {
if err := syscall.Chmod(path, uint32(hdr.Mode&07777)); err != nil {
return err
}
}
ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
// syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and
if hdr.Typeflag != tar.TypeSymlink {
if err := syscall.UtimesNano(path, ts); err != nil {
return err
}
} else {
if err := LUtimesNano(path, ts); err != nil {
return err
}
}
return nil
}
示例8: SetAttr
//.........這裏部分代碼省略.........
constor.error("Fstat failed on %s : %s", F.id, err)
return fuse.ToStatus(err)
}
attr := (*fuse.Attr)(&out.Attr)
attr.FromStat(&stat)
attr.Ino = idtoino(inode.id)
return fuse.OK
}
if inode.layer == -1 {
return fuse.ENOENT
}
if inode.layer != 0 {
err = constor.copyup(inode)
if err != nil {
constor.error("copyup failed for %s - %s", inode.id, err)
return fuse.ToStatus(err)
}
}
stat := syscall.Stat_t{}
path := constor.getPath(0, inode.id)
// just to satisfy PJD tests
if input.Valid == 0 {
err = syscall.Lchown(path, uid, gid)
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_MODE != 0 {
permissions := uint32(07777) & input.Mode
err = syscall.Chmod(path, permissions)
if err != nil {
constor.error("Lchmod failed on %s - %d : %s", path, permissions, err)
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_UID) != 0 {
uid = int(input.Uid)
}
if input.Valid&(fuse.FATTR_GID) != 0 {
gid = int(input.Gid)
}
if input.Valid&(fuse.FATTR_UID|fuse.FATTR_GID) != 0 {
constor.log("%s %d %d", path, uid, gid)
err = syscall.Lchown(path, uid, gid)
if err != nil {
constor.error("Lchown failed on %s - %d %d : %s", path, uid, gid, err)
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_SIZE != 0 {
err = syscall.Truncate(path, int64(input.Size))
if err != nil {
constor.error("Truncate failed on %s - %d : %s", path, input.Size, err)
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_ATIME|fuse.FATTR_MTIME|fuse.FATTR_ATIME_NOW|fuse.FATTR_MTIME_NOW) != 0 {
now := time.Now()
var atime *time.Time
var mtime *time.Time
示例9: 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.
func Chmod(name string, mode int) Error {
if e := syscall.Chmod(name, mode); e != 0 {
return &PathError{"chmod", name, Errno(e)}
}
return nil
}
示例10: 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.
func Chmod(name string, mode uint32) error {
if e := syscall.Chmod(name, mode); iserror(e) {
return &PathError{"chmod", name, Errno(e)}
}
return nil
}
示例11: main
func main() {
host := os.Getenv("ISUCON5_DB_HOST")
if host == "" {
host = "localhost"
}
portstr := os.Getenv("ISUCON5_DB_PORT")
if portstr == "" {
portstr = "3306"
}
port, err := strconv.Atoi(portstr)
if err != nil {
log.Fatalf("Failed to read DB port number from an environment variable ISUCON5_DB_PORT.\nError: %s", err.Error())
}
user := os.Getenv("ISUCON5_DB_USER")
if user == "" {
user = "root"
}
password := os.Getenv("ISUCON5_DB_PASSWORD")
dbname := os.Getenv("ISUCON5_DB_NAME")
if dbname == "" {
dbname = "isucon5q"
}
ssecret := os.Getenv("ISUCON5_SESSION_SECRET")
if ssecret == "" {
ssecret = "beermoris"
}
db, err = sql.Open("mysql", user+":"+password+"@tcp("+host+":"+strconv.Itoa(port)+")/"+dbname+"?loc=Local&parseTime=true")
if err != nil {
log.Fatalf("Failed to connect to DB: %s.", err.Error())
}
defer db.Close()
store = sessions.NewCookieStore([]byte(ssecret))
r := mux.NewRouter()
l := r.Path("/login").Subrouter()
l.Methods("GET").HandlerFunc(myHandler(GetLogin))
l.Methods("POST").HandlerFunc(myHandler(PostLogin))
r.Path("/logout").Methods("GET").HandlerFunc(myHandler(GetLogout))
p := r.Path("/profile/{account_name}").Subrouter()
p.Methods("GET").HandlerFunc(myHandler(GetProfile))
p.Methods("POST").HandlerFunc(myHandler(PostProfile))
d := r.PathPrefix("/diary").Subrouter()
d.HandleFunc("/entries/{account_name}", myHandler(ListEntries)).Methods("GET")
d.HandleFunc("/entry", myHandler(PostEntry)).Methods("POST")
d.HandleFunc("/entry/{entry_id}", myHandler(GetEntry)).Methods("GET")
d.HandleFunc("/comment/{entry_id}", myHandler(PostComment)).Methods("POST")
r.HandleFunc("/footprints", myHandler(GetFootprints)).Methods("GET")
r.HandleFunc("/friends", myHandler(GetFriends)).Methods("GET")
r.HandleFunc("/friends/{account_name}", myHandler(PostFriends)).Methods("POST")
r.HandleFunc("/initialize", myHandler(GetInitialize))
r.HandleFunc("/", myHandler(GetIndex))
r.PathPrefix("/").Handler(http.FileServer(http.Dir("../static")))
//log.Fatal(http.ListenAndServe(":8080", r))
listen, _ := net.Listen("unix", "/run/sock-shared/isuxi.go.sock")
syscall.Chmod("/run/sock-shared/isuxi.go.sock", 0777)
log.Fatal(http.Serve(listen, r))
}
示例12: Chmod
func (k *PosixKernel) Chmod(path string, mode uint32) uint64 {
return Errno(syscall.Chmod(path, mode))
}
示例13: copyup
func (constor *Constor) copyup(inode *Inode) error {
constor.log("%s", inode.id)
if inode.layer == 0 {
return nil
}
src := constor.getPath(inode.layer, inode.id)
if src == "" {
return syscall.EIO
}
dst := constor.getPath(0, inode.id)
if dst == "" {
return syscall.EIO
}
fi, err := os.Lstat(src)
if err != nil {
return err
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
linkName, err := os.Readlink(src)
if err != nil {
return err
}
err = os.Symlink(linkName, dst)
if err != nil {
return err
}
} else if fi.Mode()&os.ModeDir == os.ModeDir {
err := os.Mkdir(dst, fi.Mode())
if err != nil {
return err
}
} else {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, in)
if err != nil {
return err
}
err = out.Close()
if err != nil {
return err
}
}
stat := syscall.Stat_t{}
if err = syscall.Lstat(src, &stat); err != nil {
return err
}
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
if err = syscall.Chmod(dst, stat.Mode); err != nil {
return err
}
}
if err = syscall.Lchown(dst, int(stat.Uid), int(stat.Gid)); err != nil {
return err
}
links, err := Lgetxattr(src, LINKSXATTR)
if err == nil && len(links) > 0 {
err := Lsetxattr(dst, LINKSXATTR, links, 0)
if err != nil {
return err
}
}
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
if err = syscall.UtimesNano(dst, []syscall.Timespec{stat.Atim, stat.Mtim}); err != nil {
return err
}
}
inode.layer = 0
constor.log("done", inode.id)
return nil
}
示例14: Chmod
// Given a filepath, set it's permission bits directly
func Chmod(filepath string, b PermissionBits) error {
if e := syscall.Chmod(filepath, syscallMode(b)); e != nil {
return &os.PathError{"chmod", filepath, e}
}
return nil
}
示例15: SetAttr
func (constor *Constor) SetAttr(input *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status {
constor.log("%d %d", input.NodeId, input.Valid)
var err error
uid := -1
gid := -1
// if ((input.Valid & fuse.FATTR_FH) !=0) && ((input.Valid & (fuse.FATTR_ATIME | fuse.FATTR_MTIME)) == 0) {
if ((input.Valid & fuse.FATTR_FH) != 0) && ((input.Valid & fuse.FATTR_SIZE) != 0) {
ptr := uintptr(input.Fh)
F := constor.getfd(ptr)
if F == nil {
constor.error("F == nil")
return fuse.EIO
}
if F.layer != 0 {
constor.error("layer not 0")
return fuse.EIO
}
constor.log("Ftruncate %d", ptr)
err := syscall.Ftruncate(F.fd, int64(input.Size))
if err != nil {
constor.error("%s", err)
return fuse.ToStatus(err)
}
stat := syscall.Stat_t{}
err = syscall.Fstat(F.fd, &stat)
if err != nil {
constor.error("%s", err)
return fuse.ToStatus(err)
}
attr := (*fuse.Attr)(&out.Attr)
attr.FromStat(&stat)
attr.Ino = input.NodeId
return fuse.OK
}
inode, err := constor.inodemap.findInode(input.NodeId)
if err != nil {
return fuse.ToStatus(err)
}
if inode.layer != 0 {
err = constor.copyup(inode)
if err != nil {
constor.log("%s", err)
return fuse.ToStatus(err)
}
}
stat := syscall.Stat_t{}
path, err := constor.dentrymap.getPath(input.NodeId)
if err != nil {
constor.log("%s", err)
return fuse.ToStatus(err)
}
pathl := Path.Join(constor.layers[0], path)
// just to satisfy PJD tests
if input.Valid == 0 {
err = os.Lchown(pathl, uid, gid)
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_MODE != 0 {
permissions := uint32(07777) & input.Mode
err = syscall.Chmod(pathl, permissions)
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_UID) != 0 {
uid = int(input.Uid)
}
if input.Valid&(fuse.FATTR_GID) != 0 {
gid = int(input.Gid)
}
if input.Valid&(fuse.FATTR_UID|fuse.FATTR_GID) != 0 {
constor.log("%s %d %d", pathl, uid, gid)
err = os.Lchown(pathl, uid, gid)
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&fuse.FATTR_SIZE != 0 {
err = os.Truncate(pathl, int64(input.Size))
if err != nil {
return fuse.ToStatus(err)
}
}
if input.Valid&(fuse.FATTR_ATIME|fuse.FATTR_MTIME|fuse.FATTR_ATIME_NOW|fuse.FATTR_MTIME_NOW) != 0 {
now := time.Now()
var atime *time.Time
var mtime *time.Time
if input.Valid&fuse.FATTR_ATIME_NOW != 0 {
atime = &now
} else {
t := time.Unix(int64(input.Atime), int64(input.Atimensec))
atime = &t
//.........這裏部分代碼省略.........