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


Golang syscall.Mkdir函数代码示例

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


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

示例1: installKey

// TODO: install functions should be defined on an interface. Composed implementations
// would persist to various stores. This implementation will use mounted tmpfs, but others
// might include some vault.
func installKey(key *rsa.PrivateKey, location string) error {

	pkDirPrepTimeStart := time.Now()
	dir := path.Dir(location)
	// Create destination directory
	if err := syscall.Mkdir(dir, 0600); err != nil {
		if err != syscall.EEXIST {
			return err
		}
		// The directory already exists
		log.Printf("The key destination directory already exists.")
	}

	// with CAP_SYS_ADMIN we could create a tmpfs mount
	if err := syscall.Mount("tmpfs", dir, "tmpfs", 0600, "size=1M"); err != nil {
		log.Printf("Unable to create tmpfs mount. Do you have CAP_SYS_ADMIN? Error: %s", err)
	}
	log.Printf("[TIMER] [%s] Prepared PK storage\n", time.Since(pkDirPrepTimeStart))

	keyOut, err := os.OpenFile(location, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	defer keyOut.Close()

	if err != nil {
		log.Print("failed to open key.pem for writing:", err)
		return nil
	}
	pkFileWriteTimeStart := time.Now()
	pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})
	log.Printf("[TIMER] [%s] Wrote PK\n", time.Since(pkFileWriteTimeStart))
	return nil
}
开发者ID:mmtauber,项目名称:pollendina,代码行数:34,代码来源:client.go

示例2: initLog

func initLog() {
	log_level := l4g.INFO
	log_path := config.LOGGING.PATH
	syscall.Mkdir(filepath.Dir(log_path), 0755)
	log = make(l4g.Logger)
	log.AddFilter("file", log_level, l4g.NewFileLogWriter(log_path, true))
}
开发者ID:andreysorokin,项目名称:vcap-services,代码行数:7,代码来源:server_test.go

示例3: NewRun

func NewRun() *Run {
	var r Run
	r.state = STOPPED
	//	r.updatePositionMode = ACROSS_SQUARE_BORDER
	r.updatePositionMode = WITHIN_SQUARE_BORDER
	r.gridFieldNb = 10
	bodies := make([]quadtree.Body, 0)

	// create output directory and cwd to it
	r.OutputDir = time.Now().Local().Format(time.RFC3339)
	Info.Printf("Output dir %s", r.OutputDir)
	syscall.Mkdir(r.OutputDir, 0777)

	// init the file storing the gini distribution over time
	filename := fmt.Sprintf(r.OutputDir + "/gini_out.csv")
	file, err := os.Create(filename)
	if err != nil {
		log.Fatal(err)
		return nil
	}
	r.giniFileLog = file

	// init the file storing status of the run at all steps
	filename = fmt.Sprintf(r.OutputDir + "/status_out.csv")
	file, err = os.Create(filename)
	if err != nil {
		log.Fatal(err)
		return nil
	}
	r.StatusFileLog = file

	r.Init(&bodies)

	return &r
}
开发者ID:thomaspeugeot,项目名称:tkv,代码行数:35,代码来源:barnes-hut.go

示例4: Mkdir

// Mkdir creates a new directory with the specified name and permission bits.
// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error {
	e := syscall.Mkdir(name, syscallMode(perm))
	if e != nil {
		return &PathError{"mkdir", name, e}
	}
	return nil
}
开发者ID:jroelofs,项目名称:darwin-gcc-5,代码行数:9,代码来源:file.go

示例5: Mkdir

// Mkdir creates a new directory with the specified name and permission bits.
// It returns an error, if any.
func Mkdir(name string, perm uint32) Error {
	e := syscall.Mkdir(name, perm)
	if iserror(e) {
		return &PathError{"mkdir", name, Errno(e)}
	}
	return nil
}
开发者ID:richlowe,项目名称:gcc,代码行数:9,代码来源:file.go

示例6: Mkdir

// Mkdir creates a new directory with the specified name and permission bits.
// It returns an error, if any.
func Mkdir(name string, perm int) Error {
	e := syscall.Mkdir(name, perm)
	if e != 0 {
		return &PathError{"mkdir", name, Errno(e)}
	}
	return nil
}
开发者ID:lougxing,项目名称:golang-china,代码行数:9,代码来源:file.go

示例7: Mkdir

func (constor *Constor) Mkdir(input *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
	inode := constor.inodemap.findInodePtr(input.NodeId)
	if inode == nil {
		constor.error("inode == nil")
		return fuse.ENOENT
	}
	constor.log("%s %s", inode.id, name)
	err := constor.copyup(inode)
	if err != nil {
		constor.error("copyup failed on %s : ", inode.id, err)
		return fuse.ToStatus(err)
	}
	dirpath := constor.getPath(0, inode.id)
	entrypath := Path.Join(dirpath, name)
	syscall.Unlink(entrypath) // remove a deleted entry
	err = syscall.Mkdir(entrypath, input.Mode)
	if err != nil {
		constor.error("Failed on %s : %s", 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.Mkdir(path, input.Mode)
	if err != nil {
		constor.error("Mkdir failed on %s : %s", path, err)
		return fuse.ToStatus(err)
	}
	err = syscall.Chown(path, int(input.Uid), int(input.Gid))
	if err != nil {
		constor.error("Chown failed on %s : %s", path, err)
		return fuse.ToStatus(err)
	}
	return constor.Lookup((*fuse.InHeader)(unsafe.Pointer(input)), name, out)
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:42,代码来源:main.go

示例8: cmd_mkdir

func cmd_mkdir(cmd *interpreter.Interpreter) (interpreter.NextT, error) {
	if len(cmd.Args) <= 1 {
		fmt.Println("Usage: mkdir [/s] DIRECTORIES...")
		return interpreter.CONTINUE, nil
	}
	for _, arg1 := range cmd.Args[1:] {
		err := syscall.Mkdir(arg1, 0777)
		if err != nil {
			fmt.Fprintf(cmd.Stderr, "%s: %s\n", arg1, err)
		}
	}
	return interpreter.CONTINUE, nil
}
开发者ID:kissthink,项目名称:nyagos,代码行数:13,代码来源:mkdir.go

示例9: Mkdir

// Mkdir creates a new directory with the specified name and permission bits.
// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error {
	e := syscall.Mkdir(name, syscallMode(perm))

	if e != nil {
		return &PathError{"mkdir", name, e}
	}

	// mkdir(2) itself won't handle the sticky bit on *BSD and Solaris
	if !supportsCreateWithStickyBit && perm&ModeSticky != 0 {
		Chmod(name, perm)
	}

	return nil
}
开发者ID:Mahdi89,项目名称:riscv-go,代码行数:16,代码来源:file.go

示例10: cmd_mkdir

func cmd_mkdir(cmd *Interpreter) (ErrorLevel, error) {
	if len(cmd.Args) <= 1 {
		fmt.Println("Usage: mkdir [/s] DIRECTORIES...")
		return NOERROR, nil
	}
	var errorcount ErrorLevel = 0
	for _, arg1 := range cmd.Args[1:] {
		err := syscall.Mkdir(arg1, 0777)
		if err != nil {
			fmt.Fprintf(cmd.Stderr, "%s: %s\n", arg1, err)
			errorcount++
		}
	}
	return errorcount, nil
}
开发者ID:amnz,项目名称:nyagos,代码行数:15,代码来源:mkdir.go

示例11: createPath

func (constor *Constor) createPath(dirpath string) error {
	dirs := strings.Split(dirpath, "/")
	if len(dirs) == 0 {
		return syscall.EIO
	}
	subdir := ""
	for _, dir := range dirs {
		if dir == "" {
			continue
		}
		subdir = Path.Join(subdir, "/", dir)
		li := constor.getLayer(subdir)
		if li == 0 {
			continue
		}
		if li == -1 {
			return syscall.EIO
		}
		stat := syscall.Stat_t{}
		if err := constor.Lstat(subdir, &stat); err != nil {
			return err
		}
		subdirl := Path.Join(constor.layers[0], subdir)
		if err := syscall.Mkdir(subdirl, stat.Mode); err != nil {
			return err
		}
		if err := syscall.Chown(subdirl, int(stat.Uid), int(stat.Gid)); err != nil {
			return err
		}
		if err := syscall.UtimesNano(subdirl, []syscall.Timespec{stat.Atim, stat.Mtim}); err != nil {
			return err
		}
		inoitoa := strconv.Itoa(int(stat.Ino))
		inobyte := []byte(inoitoa)
		if err := syscall.Setxattr(subdirl, INOXATTR, inobyte, 0); err != nil {
			return err
		}
		inode, err := constor.inodemap.findInode(stat.Ino)
		if err != nil {
			return err
		}
		inode.Lock()
		inode.layer = 0
		inode.Unlock()
	}
	return nil
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:47,代码来源:helpers.go

示例12: log_init

func log_init(log l4g.Logger, conf *proxy.ProxyConfig) {
	log_level := l4g.INFO
	switch conf.LOGGING.LEVEL {
	case "debug":
		log_level = l4g.DEBUG
	case "info":
		log_level = l4g.INFO
	case "warning":
		log_level = l4g.WARNING
	case "error":
		log_level = l4g.ERROR
	case "critical":
		log_level = l4g.CRITICAL
	}
	log_path := conf.LOGGING.PATH
	syscall.Mkdir(filepath.Dir(log_path), 0755)
	log.AddFilter("file", log_level, l4g.NewFileLogWriter(log_path, true))
}
开发者ID:niryuu,项目名称:vcap-services,代码行数:18,代码来源:logger.go

示例13: remove

func (file *File) remove(
	fs *Fs,
	path string) error {

	file.RWMutex.Lock()
	defer file.RWMutex.Unlock()

	// Unlink what's there.
	err := file.unlink()
	if err != nil {
		return err
	}

	// Make sure the parent exists.
	err = file.makeTree(fs, path)
	if err != nil {
		file.RWMutex.Unlock()
		return err
	}

	// We need to have something we can record
	// on. Even for files we record a directory,
	// this later on packs may choose to make this
	// into a tree and we need to be ready for that.
	mode := (syscall.S_IFDIR | syscall.S_IRUSR | syscall.S_IWUSR | syscall.S_IXUSR)
	err = syscall.Mkdir(file.write_path, uint32(mode))
	if err != nil {
		return err
	}

	// Mark this file as deleted.
	err = setdelattr(file.write_path)
	if err != nil {
		return err
	}

	// We're deleted.
	file.write_exists = true
	file.write_deleted = true

	return nil
}
开发者ID:XenServerBestPractice,项目名称:novm,代码行数:42,代码来源:file.go

示例14: Mkdir

func (constor *Constor) Mkdir(input *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
	constor.log("%d %s", input.NodeId, name)
	path, err := constor.dentrymap.getPath(input.NodeId)
	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, name)
	syscall.Unlink(pathl) // remove a deleted entry
	constor.log("mkdir(%s)", pathl)
	err = syscall.Mkdir(pathl, input.Mode)
	if err != nil {
		return fuse.ToStatus(err)
	}
	err = syscall.Chown(pathl, int(input.Uid), int(input.Gid))
	if err != nil {
		return fuse.ToStatus(err)
	}
	return constor.Lookup((*fuse.InHeader)(unsafe.Pointer(input)), name, out)
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:22,代码来源:main.go

示例15: SavePrivate

func (k *Key) SavePrivate(out *string) error {
	// Create destination directory
	dir := path.Dir(*out)
	if err := syscall.Mkdir(dir, 0600); err != nil {
		if err != syscall.EEXIST {
			return err
		}
		// The key destination directory already exists.
	}

	keyOut, err := os.OpenFile(*out, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	defer keyOut.Close()

	if err != nil {
		return fmt.Errorf("failed to open key.pem for writing:", err)
	}
	privateKeyPem, err := k.ExportPrivate()

	if _, err := keyOut.Write(privateKeyPem); err != nil {
		return fmt.Errorf("failed to write key.pem:", err)
	}
	return nil
}
开发者ID:dnascimento,项目名称:symbios,代码行数:23,代码来源:key.go


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