本文整理匯總了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()
}
示例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)
}
}
示例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)
}
}
示例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"))
}
示例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()
}
示例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)
}
示例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)
}
示例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())
}
}
示例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
}
示例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)
}
}
}
示例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")
}
}
示例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
}
示例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)
}
示例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)
}
示例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
}