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


Golang os.Mkdir函数代码示例

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


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

示例1: generateSmbdConf

func generateSmbdConf() string {
	tempdir, _ := filepath.Abs("./tmp/samba")
	teardown = append(teardown, func() {
		os.RemoveAll(tempdir)
	})
	paths := [...]string{
		tempdir,
		filepath.Join(tempdir, "samaba", "private"),
		filepath.Join(tempdir, "samba", "public"),
	}
	for _, d := range paths {
		err := os.MkdirAll(d, 0755)
		if err != nil {
			log.Fatal(err)
		}
	}
	os.Mkdir(filepath.Join(tempdir, "private"), 0755)
	os.Mkdir(filepath.Join(tempdir, "public"), 0755)
	f, err := os.Create(filepath.Join(tempdir, "smbd.conf"))
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	templateText := SMB_CONF_TEMPLATE
	type Dir struct {
		Tempdir string
	}
	t, err := template.New("smb-conf").Parse(templateText)
	if err != nil {
		log.Fatal(err)
	}
	t.Execute(f, Dir{tempdir})
	return f.Name()
}
开发者ID:emperorcow,项目名称:libsmbclient-go,代码行数:34,代码来源:libsmbclient_test.go

示例2: setupMemNodeTest

func setupMemNodeTest(t *testing.T) (wd string, root Node, clean func()) {
	tmp, err := ioutil.TempDir("", "go-fuse-memnode_test")
	if err != nil {
		t.Fatalf("TempDir failed: %v", err)
	}
	back := tmp + "/backing"
	os.Mkdir(back, 0700)
	root = NewMemNodeFSRoot(back)
	mnt := tmp + "/mnt"
	os.Mkdir(mnt, 0700)

	connector := NewFileSystemConnector(root,
		&Options{
			EntryTimeout:    testTtl,
			AttrTimeout:     testTtl,
			NegativeTimeout: 0.0,
		})
	connector.SetDebug(VerboseTest())
	state, err := fuse.NewServer(connector.RawFS(), mnt, nil)
	if err != nil {
		t.Fatal("NewServer", err)
	}

	//me.state.SetDebug(false)
	state.SetDebug(VerboseTest())

	// Unthreaded, but in background.
	go state.Serve()
	return mnt, root, func() {
		state.Unmount()
		os.RemoveAll(tmp)
	}

}
开发者ID:freakmac,项目名称:adbfs,代码行数:34,代码来源:memnode_test.go

示例3: TestCreationChecks

func TestCreationChecks(t *testing.T) {
	wd, clean := setup(t)
	defer clean()

	err := os.Mkdir(wd+"/store/foo", 0755)
	CheckSuccess(err)
	os.Symlink(wd+"/ro", wd+"/store/foo/READONLY")
	CheckSuccess(err)

	err = os.Mkdir(wd+"/store/ws2", 0755)
	CheckSuccess(err)
	os.Symlink(wd+"/ro", wd+"/store/ws2/READONLY")
	CheckSuccess(err)

	err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/bar")
	CheckSuccess(err)

	err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/foo")
	code := fuse.ToStatus(err)
	if code != fuse.EBUSY {
		t.Error("Should return EBUSY", err)
	}

	err = os.Symlink(wd+"/store/ws2", wd+"/mnt/config/config")
	code = fuse.ToStatus(err)
	if code != fuse.EINVAL {
		t.Error("Should return EINVAL", err)
	}
}
开发者ID:crazy2be,项目名称:go-fuse,代码行数:29,代码来源:autounion_test.go

示例4: TestGetProjectRoot

func TestGetProjectRoot(t *testing.T) {
	t.Parallel()
	h := NewHarness(t)
	h.MakeEmptyRoot()
	defer h.Stop()

	ensure.Nil(t, os.Mkdir(filepath.Join(h.Env.Root, "parse"), 0755))
	ensure.Nil(t, os.Mkdir(filepath.Join(h.Env.Root, "parse", "config"), 0755))
	f, err := os.Create(filepath.Join(h.Env.Root, "parse", LegacyConfigFile))
	ensure.Nil(t, err)
	defer f.Close()
	ensure.Nil(t, os.Mkdir(filepath.Join(h.Env.Root, "parse", "cloud"), 0755))
	ensure.Nil(t, os.Mkdir(filepath.Join(h.Env.Root, "parse", "public"), 0755))
	ensure.Nil(t, os.MkdirAll(filepath.Join(h.Env.Root, "parse", "cloud", "other", "config"), 0755))

	ensure.DeepEqual(t, GetLegacyProjectRoot(h.Env, h.Env.Root), h.Env.Root)

	ensure.DeepEqual(t, GetLegacyProjectRoot(h.Env, filepath.Join(h.Env.Root, "parse", "config")), filepath.Join(h.Env.Root, "parse"))

	ensure.DeepEqual(t, GetLegacyProjectRoot(h.Env, filepath.Join(h.Env.Root, "parse", "cloud")), filepath.Join(h.Env.Root, "parse"))

	ensure.DeepEqual(t, GetLegacyProjectRoot(h.Env, filepath.Join(h.Env.Root, "parse", "public")), filepath.Join(h.Env.Root, "parse"))

	ensure.DeepEqual(t, GetLegacyProjectRoot(h.Env, filepath.Join(h.Env.Root, "parse", "cloud", "other")), filepath.Join(h.Env.Root, "parse"))
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:25,代码来源:config_test.go

示例5: main

func main() {
	var err error
	binary, err = ioutil.ReadFile("target")
	if err != nil {
		log.Panicf("Couldn't load target")
	}

	fatal := func() {
		log.Fatal("Couldn't make server workdir, maybe you already have one?")
	}

	err = os.Mkdir("work-server", 0755)
	if err != nil {
		fatal()
	}

	err = os.Mkdir("work-server/hangs", 0755)
	if err != nil {
		fatal()
	}

	err = os.Mkdir("work-server/crashes", 0755)
	if err != nil {
		fatal()
	}

	setupAndServe()
}
开发者ID:zhuyue1314,项目名称:roving,代码行数:28,代码来源:main.go

示例6: build

func (h requestHandler) build(req BuildRequest, incremental bool) (*BuildResult, error) {
	if h.debug {
		log.Printf("Performing source build from %s\n", req.Source)
	}

	workingTmpDir := filepath.Join(req.WorkingDir, "tmp")
	err := os.Mkdir(workingTmpDir, 0700)
	if err != nil {
		return nil, err
	}

	if incremental {

		artifactTmpDir := filepath.Join(req.WorkingDir, "artifacts")
		err = os.Mkdir(artifactTmpDir, 0700)
		if err != nil {
			return nil, err
		}

		err = h.saveArtifacts(req.Tag, workingTmpDir, artifactTmpDir)
		if err != nil {
			return nil, err
		}
	}

	targetSourceDir := filepath.Join(req.WorkingDir, "src")
	err = h.prepareSourceDir(req.Source, targetSourceDir)
	if err != nil {
		return nil, err
	}

	return h.buildDeployableImage(req, req.BaseImage, req.WorkingDir, incremental)
}
开发者ID:jhadvig,项目名称:go-sti,代码行数:33,代码来源:build.go

示例7: TestOriginalIsSymlink

func TestOriginalIsSymlink(t *testing.T) {
	tmpDir, err := ioutil.TempDir("", "go-fuse")
	CheckSuccess(err)
	defer os.RemoveAll(tmpDir)
	orig := tmpDir + "/orig"
	err = os.Mkdir(orig, 0755)
	CheckSuccess(err)
	link := tmpDir + "/link"
	mnt := tmpDir + "/mnt"
	err = os.Mkdir(mnt, 0755)
	CheckSuccess(err)
	err = os.Symlink("orig", link)
	CheckSuccess(err)

	fs := NewLoopbackFileSystem(link)
	nfs := NewPathNodeFs(fs, nil)
	state, _, err := MountNodeFileSystem(mnt, nfs, nil)
	CheckSuccess(err)
	defer state.Unmount()

	go state.Loop()

	_, err = os.Lstat(mnt)
	CheckSuccess(err)
}
开发者ID:niltonkummer,项目名称:go-fuse,代码行数:25,代码来源:loopback_test.go

示例8: main

func main() {
	flag.Parse()

	os.Mkdir(*cache, 0755)
	os.Mkdir(*folder, 0755)
	ListFolder()

	http.HandleFunc("/images/", GetImages)
	http.HandleFunc("/select", SelectImage)
	http.HandleFunc("/upload", UploadImage)
	http.HandleFunc("/screen", Screen)

	http.Handle("/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "static"}))

	fmt.Println("Digital signage demo by Visionect")
	fmt.Println("http://www.visionect.com")
	fmt.Printf("\nStarting server at: http://%s:%s/ \n", *address, *port)
	fmt.Printf("Serving images from: %s \n", *folder)
	fmt.Println("\nHelp available with -h, exit with Ctrl-C")

	err := http.ListenAndServe(*address+":"+*port, nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
开发者ID:yashodhank,项目名称:digitalsignage,代码行数:25,代码来源:digitalsignage.go

示例9: 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.Mkdir(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.Mkdir(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:shadabahmed,项目名称:nomad,代码行数:29,代码来源:alloc_dir_linux.go

示例10: setupCacheTest

func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
	dir := testutil.TempDir()
	os.Mkdir(dir+"/mnt", 0755)
	os.Mkdir(dir+"/orig", 0755)

	fs := &cacheFs{
		pathfs.NewLoopbackFileSystem(dir + "/orig"),
	}
	pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: testutil.VerboseTest()})

	opts := nodefs.NewOptions()
	opts.Debug = testutil.VerboseTest()
	state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), opts)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	go state.Serve()
	if err := state.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}
	return dir, pfs, func() {
		err := state.Unmount()
		if err == nil {
			os.RemoveAll(dir)
		}
	}
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:27,代码来源:cache_test.go

示例11: TestRepoAdd

func TestRepoAdd(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		fmt.Fprintln(w, "OK")
	}))

	helmHome, _ = ioutil.TempDir("", "helm_home")
	defer os.Remove(helmHome)
	os.Mkdir(filepath.Join(helmHome, repositoryDir), 0755)
	os.Mkdir(cacheDirectory(), 0755)

	if err := ioutil.WriteFile(repositoriesFile(), []byte("example-repo: http://exampleurl.com"), 0666); err != nil {
		t.Errorf("%#v", err)
	}

	if err := addRepository(testName, ts.URL); err != nil {
		t.Errorf("%s", err)
	}

	f, err := repo.LoadRepositoriesFile(repositoriesFile())
	if err != nil {
		t.Errorf("%s", err)
	}
	_, ok := f.Repositories[testName]
	if !ok {
		t.Errorf("%s was not successfully inserted into %s", testName, repositoriesFile())
	}

	if err := insertRepoLine(testName, ts.URL); err == nil {
		t.Errorf("Duplicate repository name was added")
	}

}
开发者ID:Chronojam,项目名称:helm,代码行数:33,代码来源:repo_test.go

示例12: buildHash

func (b *Builder) buildHash(hash string) error {
	log.Println(b.name, "building", hash)

	// create place in which to do work
	workpath := filepath.Join(*buildroot, b.name+"-"+hash[:12])
	if err := os.Mkdir(workpath, mkdirPerm); err != nil {
		if err2 := removePath(workpath); err2 != nil {
			return err
		}
		if err := os.Mkdir(workpath, mkdirPerm); err != nil {
			return err
		}
	}
	defer removePath(workpath)

	buildLog, runTime, err := b.buildRepoOnHash(workpath, hash, b.buildCmd())
	if err != nil {
		// record failure
		return b.recordResult(false, "", hash, "", buildLog, runTime)
	}

	// record success
	if err = b.recordResult(true, "", hash, "", "", runTime); err != nil {
		return fmt.Errorf("recordResult: %s", err)
	}

	if *buildTool == "go" {
		// build sub-repositories
		goRoot := filepath.Join(workpath, *buildTool)
		goPath := workpath
		b.buildSubrepos(goRoot, goPath, hash)
	}

	return nil
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:35,代码来源:main.go

示例13: createRepositoryTree

func createRepositoryTree(absFolderPath string) error {
	if err := os.Mkdir(absFolderPath, 0755); err != nil {
		return err
	}

	brigPath := filepath.Join(absFolderPath, ".brig")
	if err := os.Mkdir(brigPath, 0755); err != nil {
		return err
	}

	ipfsPath := filepath.Join(brigPath, "ipfs")
	if err := os.Mkdir(ipfsPath, 0755); err != nil {
		return err
	}

	empties := []string{"otr.key", "otr.buddies", "shadow", "remotes.yml"}
	for _, empty := range empties {
		fullPath := filepath.Join(brigPath, empty)
		if err := util.Touch(fullPath); err != nil {
			return err
		}
	}

	// Make the key larger than needed:
	if err := createMasterKey(brigPath, 1024); err != nil {
		return err
	}

	return CreateIpfsRepo(ipfsPath)
}
开发者ID:disorganizer,项目名称:brig,代码行数:30,代码来源:init.go

示例14: tearDownTests

func tearDownTests() {
	storage.CloseInfoDB()
	os.RemoveAll(config.GetConfig().GetDataDir())
	os.RemoveAll(config.GetConfig().GetInfoDir())
	os.Mkdir(config.GetConfig().GetDataDir(), 0777)
	os.Mkdir(config.GetConfig().GetInfoDir(), 0777)
}
开发者ID:postfix,项目名称:skizze,代码行数:7,代码来源:manager_test.go

示例15: Create

func (d MailDir) Create() (err error) {
	err = os.Mkdir(d.String(), 0700)
	err = os.Mkdir(filepath.Join(d.String(), "new"), 0700)
	err = os.Mkdir(filepath.Join(d.String(), "cur"), 0700)
	err = os.Mkdir(filepath.Join(d.String(), "tmp"), 0700)
	return
}
开发者ID:str4d,项目名称:i2p-tools,代码行数:7,代码来源:maildir.go


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