当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Lchown函数代码示例

本文整理汇总了Golang中syscall.Lchown函数的典型用法代码示例。如果您正苦于以下问题:Golang Lchown函数的具体用法?Golang Lchown怎么用?Golang Lchown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Lchown函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Symlink

func (constor *Constor) Symlink(header *fuse.InHeader, pointedTo string, linkName string, out *fuse.EntryOut) (code fuse.Status) {
	inode := constor.inodemap.findInodePtr(header.NodeId)
	if inode == nil {
		constor.error("inode == nil")
		return fuse.ENOENT
	}
	err := constor.copyup(inode)
	if err != nil {
		constor.error("copyup failed for %s - %s", inode.id, err)
		return fuse.ToStatus(err)
	}
	dirpath := constor.getPath(0, inode.id)
	entrypath := Path.Join(dirpath, linkName)

	constor.log("%s <- %s/%s", pointedTo, inode.id, linkName)
	syscall.Unlink(entrypath) // remove a deleted entry
	err = syscall.Symlink(pointedTo, entrypath)
	if err != nil {
		constor.error("Symlink failed %s <- %s : %s", pointedTo, entrypath, err)
		return fuse.ToStatus(err)
	}
	id := constor.setid(entrypath, "")
	if id == "" {
		constor.error("setid failed on %s", entrypath)
		return fuse.ENOENT
	}
	if err := constor.createPath(id); err != nil {
		constor.error("createPath failed on %s : %s", id, err)
		return fuse.ToStatus(err)
	}
	path := constor.getPath(0, id)
	err = syscall.Symlink(pointedTo, path)
	if err != nil {
		constor.error("Symlink failed %s <- %s : %s", pointedTo, path, err)
		return fuse.ToStatus(err)
	}
	err = syscall.Lchown(path, int(header.Uid), int(header.Gid))
	if err != nil {
		constor.error("Chown failed on %s : %s", path, err)
		return fuse.ToStatus(err)
	}
	return constor.Lookup(header, linkName, out)
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:43,代码来源:main.go

示例2: Symlink

func (constor *Constor) Symlink(header *fuse.InHeader, pointedTo string, linkName string, out *fuse.EntryOut) (code fuse.Status) {
	constor.log("%d %s <- %s, uid: %d, gid: %d", header.NodeId, pointedTo, linkName, header.Uid, header.Gid)
	parentino := header.NodeId
	path, err := constor.dentrymap.getPath(parentino)
	if err != nil {
		return fuse.ToStatus(err)
	}
	if err = constor.createPath(path); err != nil {
		return fuse.ToStatus(err)
	}
	pathl := Path.Join(constor.layers[0], path, linkName)
	syscall.Unlink(pathl) // remove a deleted entry
	err = syscall.Symlink(pointedTo, pathl)
	if err != nil {
		return fuse.ToStatus(err)
	}
	err = syscall.Lchown(pathl, int(header.Uid), int(header.Gid))
	if err != nil {
		return fuse.ToStatus(err)
	}
	return constor.Lookup(header, linkName, out)
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:22,代码来源:main.go

示例3: ApplyLayer


//.........这里部分代码省略.........
					hasDir = true
				} else {
					if err := os.RemoveAll(path); err != nil {
						return err
					}
				}
			}

			switch hdr.Typeflag {
			case tar.TypeDir:
				if !hasDir {
					err = os.Mkdir(path, os.FileMode(hdr.Mode))
					if err != nil {
						return err
					}
				}
				dirs = append(dirs, hdr)

			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, tr); 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(dest, hdr.Linkname), path); err != nil {
					return err
				}

			case tar.TypeSymlink:
				if err := os.Symlink(hdr.Linkname, path); err != nil {
					return err
				}

			default:
				utils.Debugf("unhandled 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 {
				err = syscall.Chmod(path, uint32(hdr.Mode&07777))
				if err != nil {
					return err
				}
			}

			// Directories must be handled at the end to avoid further
			// file creation in them to modify the mtime
			if hdr.Typeflag != tar.TypeDir {
				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
					}
				}
			}
		}
	}

	for _, hdr := range dirs {
		path := filepath.Join(dest, hdr.Name)
		ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
		if err := syscall.UtimesNano(path, ts); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:neil-rubens,项目名称:docker,代码行数:101,代码来源:diff.go

示例4: Lchown

// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
// If there is an error, it will be of type *PathError.
func Lchown(name string, uid, gid int) error {
	if e := syscall.Lchown(name, uid, gid); e != nil {
		return &PathError{"lchown", name, e}
	}
	return nil
}
开发者ID:ds2dev,项目名称:gcc,代码行数:9,代码来源:file_posix.go

示例5: Lchown

// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
func Lchown(name string, uid, gid int) Error {
	if e := syscall.Lchown(name, uid, gid); e != 0 {
		return &PathError{"lchown", name, Errno(e)}
	}
	return nil
}
开发者ID:lougxing,项目名称:golang-china,代码行数:8,代码来源:file.go

示例6: 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
}
开发者ID:Nerdness,项目名称:docker,代码行数:81,代码来源:archive.go

示例7: copyup

func (constor *Constor) copyup(inode *Inode) error {
	src, err := constor.getPath(inode.ino)
	if err != nil {
		return err
	}
	dst, err := constor.dentrymap.getPath(inode.ino)
	if err != nil {
		return err
	}
	err = constor.createPath(Path.Dir(dst))
	if err != nil {
		return err
	}
	dst = Path.Join(constor.layers[0], dst)
	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
	}
	if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
		if err = syscall.UtimesNano(dst, []syscall.Timespec{stat.Atim, stat.Mtim}); err != nil {
			return err
		}
	}
	inoitoa := strconv.Itoa(int(stat.Ino))
	inobyte := []byte(inoitoa)
	// if err = syscall.Setxattr(dst, INOXATTR, inobyte, 0); err != nil {
	// 	return err
	// }
	if err = Lsetxattr(dst, INOXATTR, inobyte, 0); err != nil {
		return err
	}
	inode.layer = 0
	path, err := constor.dentrymap.getPath(inode.ino)
	constor.log("ino %d file %s", inode.ino, path)
	return nil
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:82,代码来源:helpers.go

示例8: Lchown

func (k *PosixKernel) Lchown(path string, uid, gid int) uint64 {
	return Errno(syscall.Lchown(path, uid, gid))
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:3,代码来源:io.go

示例9: 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
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:80,代码来源:helpers.go

示例10: SetAttr


//.........这里部分代码省略.........
				return fuse.ToStatus(err)
			}
		}

		stat := syscall.Stat_t{}
		err = syscall.Fstat(F.fd, &stat)
		if err != nil {
			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)
开发者ID:krishnasrinivas,项目名称:confs,代码行数:67,代码来源:main.go


注:本文中的syscall.Lchown函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。