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


Golang os.MkdirAll函数代码示例

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


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

示例1: authInit

func authInit() {
	os.MkdirAll(path.Join(common.BaseDir, "auth"), 0755)
	err := os.RemoveAll(path.Join(common.BaseDir, "auth", "secure"))
	if err != nil {
		log.Printf("Failed to clean out the secure directory. %v\n", err)
		os.Exit(-1)
	}
	err = os.RemoveAll(path.Join(common.BaseDir, "auth", "user"))
	if err != nil {
		log.Printf("Failed to clean out the user directory. %v\n", err)
		os.Exit(-1)
	}
	os.MkdirAll(path.Join(common.BaseDir, "auth", "user"), 0755)
	os.MkdirAll(path.Join(common.BaseDir, "auth", "secure"), 0700)
	if common.System && platform.PlatformGet() == platform.Windows {
		err = common.Cacls(path.Join(common.BaseDir, "auth", "secure"), "/p", "NT AUTHORITY\\SYSTEM:f", "BUILTIN\\Administrators:F")
		if err != nil {
			log.Printf("Failed to run cacls %v\n", err)
			os.Exit(-1)
		}
		err = common.Cacls(path.Join(common.BaseDir, "auth", "user"), "/p", "NT AUTHORITY\\SYSTEM:f", "BUILTIN\\Users:r", "BUILTIN\\Administrators:F")
		if err != nil {
			log.Printf("Failed to run cacls on auth user %v\n", err)
			os.Exit(-1)
		}
	}
}
开发者ID:EMSL-MSC,项目名称:pacifica-uploader-2.0,代码行数:27,代码来源:auth.go

示例2: MountSpecialDirs

// MountSpecialDirs mounts the dev and proc file system from the host to the
// chroot
func (d *AllocDir) MountSpecialDirs(taskDir string) error {
	// Mount dev
	dev := filepath.Join(taskDir, "dev")
	if !d.pathExists(dev) {
		if err := os.MkdirAll(dev, 0777); err != nil {
			return fmt.Errorf("Mkdir(%v) failed: %v", dev, err)
		}

		if err := syscall.Mount("none", dev, "devtmpfs", syscall.MS_RDONLY, ""); err != nil {
			return fmt.Errorf("Couldn't mount /dev to %v: %v", dev, err)
		}
	}

	// Mount proc
	proc := filepath.Join(taskDir, "proc")
	if !d.pathExists(proc) {
		if err := os.MkdirAll(proc, 0777); err != nil {
			return fmt.Errorf("Mkdir(%v) failed: %v", proc, err)
		}

		if err := syscall.Mount("none", proc, "proc", syscall.MS_RDONLY, ""); err != nil {
			return fmt.Errorf("Couldn't mount /proc to %v: %v", proc, err)
		}
	}

	return nil
}
开发者ID:achanda,项目名称:nomad,代码行数:29,代码来源:alloc_dir_linux.go

示例3: MakeClientCertificate

func (ca *CA) MakeClientCertificate(certFile, keyFile string, u user.Info) (*TLSCertificateConfig, error) {
	glog.V(4).Infof("Generating client cert in %s and key in %s", certFile, keyFile)
	// ensure parent dirs
	if err := os.MkdirAll(filepath.Dir(certFile), os.FileMode(0755)); err != nil {
		return nil, err
	}
	if err := os.MkdirAll(filepath.Dir(keyFile), os.FileMode(0755)); err != nil {
		return nil, err
	}

	clientPublicKey, clientPrivateKey, _ := NewKeyPair()
	clientTemplate, _ := newClientCertificateTemplate(x509request.UserToSubject(u))
	clientCrt, _ := ca.signCertificate(clientTemplate, clientPublicKey)

	certData, err := encodeCertificates(clientCrt)
	if err != nil {
		return nil, err
	}
	keyData, err := encodeKey(clientPrivateKey)
	if err != nil {
		return nil, err
	}

	if err = ioutil.WriteFile(certFile, certData, os.FileMode(0644)); err != nil {
		return nil, err
	}
	if err = ioutil.WriteFile(keyFile, keyData, os.FileMode(0600)); err != nil {
		return nil, err
	}

	return GetTLSCertificateConfig(certFile, keyFile)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:32,代码来源:crypto.go

示例4: TestCopyFileWithTarSrcFile

func TestCopyFileWithTarSrcFile(t *testing.T) {
	folder, err := ioutil.TempDir("", "docker-archive-test")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(folder)
	dest := filepath.Join(folder, "dest")
	srcFolder := filepath.Join(folder, "src")
	src := filepath.Join(folder, filepath.Join("src", "src"))
	err = os.MkdirAll(srcFolder, 0740)
	if err != nil {
		t.Fatal(err)
	}
	err = os.MkdirAll(dest, 0740)
	if err != nil {
		t.Fatal(err)
	}
	ioutil.WriteFile(src, []byte("content"), 0777)
	err = CopyWithTar(src, dest+"/")
	if err != nil {
		t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err)
	}
	_, err = os.Stat(dest)
	if err != nil {
		t.Fatalf("Destination folder should contain the source file but did not.")
	}
}
开发者ID:truedays,项目名称:docker,代码行数:27,代码来源:archive_test.go

示例5: SetUpTest

func (s *PartitionTestSuite) SetUpTest(c *C) {
	dirs.SetRootDir(c.MkDir())
	err := os.MkdirAll((&grub{}).Dir(), 0755)
	c.Assert(err, IsNil)
	err = os.MkdirAll((&uboot{}).Dir(), 0755)
	c.Assert(err, IsNil)
}
开发者ID:robert-ancell,项目名称:snapd,代码行数:7,代码来源:bootloader_test.go

示例6: InitDiffFile

func InitDiffFile() error {
	file1Data := "3"
	file2Data := "2"
	file3Data := "1"

	if err := os.MkdirAll(path.Join(diffTempDir, "1"), 0755); err != nil {
		return err
	}
	if err := os.MkdirAll(path.Join(diffTempDir, "2"), 0755); err != nil {
		return err
	}
	if err := os.MkdirAll(path.Join(diffTempDir, "3"), 0755); err != nil {
		return err
	}
	if err := ioutil.WriteFile(path.Join(diffTempDir, "1")+"/1", []byte(file1Data), 0755); err != nil {
		return err
	}
	if err := ioutil.WriteFile(path.Join(diffTempDir, "2")+"/2", []byte(file2Data), 0755); err != nil {
		return err
	}
	if err := ioutil.WriteFile(path.Join(diffTempDir, "3")+"/3", []byte(file3Data), 0755); err != nil {
		return err
	}

	return nil
}
开发者ID:m1911,项目名称:hyper,代码行数:26,代码来源:aufs_test.go

示例7: TestMount

func TestMount(t *testing.T) {
	graph := tempGraph(t)
	defer os.RemoveAll(graph.Root)
	archive, err := fakeTar()
	if err != nil {
		t.Fatal(err)
	}
	image, err := graph.Create(archive, nil, "Testing", "", nil)
	if err != nil {
		t.Fatal(err)
	}
	tmp, err := ioutil.TempDir("", "docker-test-graph-mount-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	rootfs := path.Join(tmp, "rootfs")
	if err := os.MkdirAll(rootfs, 0700); err != nil {
		t.Fatal(err)
	}
	rw := path.Join(tmp, "rw")
	if err := os.MkdirAll(rw, 0700); err != nil {
		t.Fatal(err)
	}
	if err := image.Mount(rootfs, rw); err != nil {
		t.Fatal(err)
	}
	// FIXME: test for mount contents
	defer func() {
		if err := Unmount(rootfs); err != nil {
			t.Error(err)
		}
	}()
}
开发者ID:nisaacson,项目名称:docker,代码行数:34,代码来源:graph_test.go

示例8: fetchCamliSrc

func fetchCamliSrc() {
	check(os.MkdirAll("/gopath/src/camlistore.org", 0777))
	check(os.Chdir("/gopath/src/camlistore.org"))

	res, err := http.Get("https://camlistore.googlesource.com/camlistore/+archive/" + *rev + ".tar.gz")
	check(err)
	defer res.Body.Close()
	gz, err := gzip.NewReader(res.Body)
	check(err)
	defer gz.Close()
	tr := tar.NewReader(gz)
	for {
		h, err := tr.Next()
		if err == io.EOF {
			break
		}
		check(err)
		if h.Typeflag == tar.TypeDir {
			check(os.MkdirAll(h.Name, os.FileMode(h.Mode)))
			continue
		}
		f, err := os.Create(h.Name)
		check(err)
		n, err := io.Copy(f, tr)
		if err != nil && err != io.EOF {
			log.Fatal(err)
		}
		if n != h.Size {
			log.Fatalf("Error when creating %v: wanted %v bytes, got %v bytes", h.Name, h.Size, n)
		}
		check(f.Close())
	}
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:33,代码来源:build-binaries.go

示例9: Download

func Download(url string) (string, error) {

	ext := strings.ToLower(path.Ext(url))
	filename := helper.MD5(time.Now().String()) + ext
	ipath := "./file/" + "download/" //time.Now().Format("03/04/")
	if !helper.Exist(ipath) {
		os.MkdirAll(ipath, 0644)
	}

	path := ipath + filename
	if e := helper.GetFile(url, path, "default", "http://www.mzitu.com/"); e == nil {

		filehash, _ := helper.Filehash(path, nil)
		fname := helper.Encrypt_hash(filehash+"1", nil)
		if ext == "" {
			ext = ".jpg"
		}
		opath := "./file/" + time.Now().Format("03/04/")
		if !helper.Exist(opath) {
			os.MkdirAll(opath, 0644)
		}

		finalpath := opath + fname + ext

		fmt.Println("path:", path)
		fmt.Println("finalpath:", finalpath)
		if e := helper.MoveFile(path, finalpath); e == nil {
			return finalpath, e
		}

	} else {
		return "", errors.New("下载错误!")
	}
	return "", errors.New("Download函数出现错误!")
}
开发者ID:rose312,项目名称:mzr,代码行数:35,代码来源:mzs.go

示例10: UnTar

// UnTar a tar file
func UnTar(srcTar string, dstDir string) (err error) {
	// 清理路径字符串
	dstDir = path.Clean(dstDir) + string(os.PathSeparator)

	fr, er := os.Open(srcTar)
	if er != nil {
		return er
	}
	defer fr.Close()

	tr := tar.NewReader(fr)

	for hdr, er := tr.Next(); er != io.EOF; hdr, er = tr.Next() {
		if er != nil {
			return er
		}

		fi := hdr.FileInfo()

		dstFullPath := dstDir + hdr.Name

		if hdr.Typeflag == tar.TypeDir {
			os.MkdirAll(dstFullPath, fi.Mode().Perm())
			os.Chmod(dstFullPath, fi.Mode().Perm())
		} else {
			os.MkdirAll(path.Dir(dstFullPath), os.ModePerm)
			if er := unTarFile(dstFullPath, tr); er != nil {
				return er
			}
			os.Chmod(dstFullPath, fi.Mode().Perm())
		}
	}
	return nil
}
开发者ID:icsnju,项目名称:apt-mesos,代码行数:35,代码来源:tar.go

示例11: TestMount

func TestMount(t *testing.T) {
	graph, driver := tempGraph(t)
	defer os.RemoveAll(graph.Root)
	defer driver.Cleanup()

	archive, err := fakeTar()
	if err != nil {
		t.Fatal(err)
	}
	image, err := graph.Create(archive, "", "", "Testing", "", nil, nil)
	if err != nil {
		t.Fatal(err)
	}
	tmp, err := ioutil.TempDir("", "docker-test-graph-mount-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	rootfs := path.Join(tmp, "rootfs")
	if err := os.MkdirAll(rootfs, 0700); err != nil {
		t.Fatal(err)
	}
	rw := path.Join(tmp, "rw")
	if err := os.MkdirAll(rw, 0700); err != nil {
		t.Fatal(err)
	}

	if _, err := driver.Get(image.ID, ""); err != nil {
		t.Fatal(err)
	}
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:31,代码来源:graph_test.go

示例12: init

// init is used to initialize the client and perform any setup
// needed before we begin starting its various components.
func (c *Client) init() error {
	// Ensure the state dir exists if we have one
	if c.config.StateDir != "" {
		if err := os.MkdirAll(c.config.StateDir, 0700); err != nil {
			return fmt.Errorf("failed creating state dir: %s", err)
		}

	} else {
		// Othewise make a temp directory to use.
		p, err := ioutil.TempDir("", "NomadClient")
		if err != nil {
			return fmt.Errorf("failed creating temporary directory for the StateDir: %v", err)
		}
		c.config.StateDir = p
	}
	c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir)

	// Ensure the alloc dir exists if we have one
	if c.config.AllocDir != "" {
		if err := os.MkdirAll(c.config.AllocDir, 0755); err != nil {
			return fmt.Errorf("failed creating alloc dir: %s", err)
		}
	} else {
		// Othewise make a temp directory to use.
		p, err := ioutil.TempDir("", "NomadClient")
		if err != nil {
			return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err)
		}
		c.config.AllocDir = p
	}

	c.logger.Printf("[INFO] client: using alloc directory %v", c.config.AllocDir)
	return nil
}
开发者ID:tbartelmess,项目名称:nomad,代码行数:36,代码来源:client.go

示例13: main

func main() {
	defer func() {
		if isDelete {
			os.RemoveAll(fpath0)
		}
	}()

	if err := os.MkdirAll(fpath0, 0700); err != nil {
		panic(err)
	}

	if existDir(fpath1) {
		fmt.Println(fpath1, "already exists... skipping...")
		return
	}

	if err := os.MkdirAll(fpath1, 0700); err != nil {
		panic(err)
	}

	if err := toFileWriteString("hello world!", fpath2); err != nil {
		panic(err)
	}

	fmt.Println("Done")
	isDelete = true
}
开发者ID:xqbumu,项目名称:learn,代码行数:27,代码来源:22_directory.go

示例14: doSave

func doSave() error {
	// Create the necessary directories
	err := os.MkdirAll(config.root, 0700)
	if err != nil {
		return err
	}

	err = os.MkdirAll(filepath.Join(config.root, "public"), 0755)
	if err != nil {
		return err
	}

	err = os.MkdirAll(filepath.Join(config.root, "content"), 0700)
	if err != nil {
		return err
	}

	err = os.MkdirAll(filepath.Join(config.root, "templates"), 0700)
	if err != nil {
		return err
	}

	data, err := json.MarshalIndent(&config, "", "  ")
	if err != nil {
		return err
	}

	file := filepath.Join(config.root, "profile.conf")
	return ioutil.WriteFile(file, data, 0600)
}
开发者ID:jteeuwen,项目名称:blargh,代码行数:30,代码来源:api.go

示例15: serve

func serve(c *cli.Context) {
	// Ensure api socket directory exists; if not, create it
	apiSocket := getApiSocket(c)
	if _, err := os.Stat(apiSocket); os.IsNotExist(err) {
		os.MkdirAll(path.Dir(apiSocket), 0777)
	}

	d := dokku.New()

	// If caching is enabled, create cache socket if necessary and launch cache
	// server in the background
	if !c.BoolT("enable-cache") {
		cacheSocket := getCacheSocket(c)
		if _, err := os.Stat(cacheSocket); os.IsNotExist(err) {
			os.MkdirAll(path.Dir(cacheSocket), 0777)
		}

		go func() {
			err := listenCache(d, cacheSocket)
			if err != nil {
				panic(err)
			}
		}()
	}

	// Start api server
	err := listenAPI(d, apiSocket)
	if err != nil {
		panic(err)
	}
}
开发者ID:nikelmwann,项目名称:dokku-api-server,代码行数:31,代码来源:main.go


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