コード例 #1
1
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
0
ファイル: memnode_test.go プロジェクト: freakmac/adbfs
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
0
ファイル: autounion_test.go プロジェクト: crazy2be/go-fuse
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
0
ファイル: config_test.go プロジェクト: swhitley/parse-cli
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
0
ファイル: main.go プロジェクト: zhuyue1314/roving
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
0
ファイル: build.go プロジェクト: jhadvig/go-sti
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
0
ファイル: loopback_test.go プロジェクト: niltonkummer/go-fuse
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
0
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
0
ファイル: alloc_dir_linux.go プロジェクト: shadabahmed/nomad
// 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
0
ファイル: cache_test.go プロジェクト: jszwedko/ec2-metadatafs
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
0
ファイル: repo_test.go プロジェクト: Chronojam/helm
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
0
ファイル: main.go プロジェクト: dylanpoe/golang.org
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
0
ファイル: init.go プロジェクト: disorganizer/brig
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
0
ファイル: manager_test.go プロジェクト: postfix/skizze
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
0
ファイル: maildir.go プロジェクト: str4d/i2p-tools
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
}
コード例 #16
0
ファイル: volume.go プロジェクト: dockware/volplugin
// Mount maps an RBD image and mount it on /mnt/ceph/<datastore>/<volume> directory
// FIXME: Figure out how to use rbd locks
func (cv *CephVolume) Mount() error {
	cd := cv.driver
	// Directory to mount the volume
	dataStoreDir := filepath.Join(cd.mountBase, cd.PoolName)
	volumeDir := filepath.Join(dataStoreDir, cv.VolumeName)

	devName, err := cv.mapImage()
	if err != nil {
		return err
	}

	// Create directory to mount
	if err := os.Mkdir(cd.mountBase, 0700); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", cd.mountBase, err)
	}

	if err := os.Mkdir(dataStoreDir, 0700); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", dataStoreDir)
	}

	if err := os.Mkdir(volumeDir, 0777); err != nil && !os.IsExist(err) {
		return fmt.Errorf("error creating %q directory: %v", volumeDir)
	}

	// Mount the RBD
	if err := syscall.Mount(devName, volumeDir, "ext4", 0, ""); err != nil && err != syscall.EBUSY {
		return fmt.Errorf("Failed to mount RBD dev %q: %v", devName, err.Error())
	}

	return nil
}
コード例 #17
0
ファイル: main.go プロジェクト: Stromausfall/ssmpg
func main() {
	// validate arguments
	configFile, baseHtml, contentFolder, outputPath := input.BasicValidationOfConsoleArguments(os.Args[1:])

	/*
		configFile := "C:/Users/Matthias/OneDrive/GO/ssmpg/input/test.yaml"
		baseHtml := "C:/Users/Matthias/OneDrive/GO/ssmpg/input/base.html"
		contentFolder := "C:/Users/Matthias/OneDrive/GO/ssmpg/input/content"
		outputPath := "C:/xxx/output/"
	*/

	os.Mkdir(filepath.Join(outputPath, "content"), 777)
	os.Mkdir(filepath.Join(outputPath, "categories"), 777)

	configData := input.CreateConfigData(configFile)
	baseHtmlContent := input.LoadBaseHtmlData(baseHtml)
	contentData := input.LoadContentData(contentFolder)

	// create index
	page.CreateIndexPage(outputPath, configData, contentData, baseHtmlContent)

	// create category pages
	categories := sidebar.CollectCategories(contentData)

	// we need to synchronize the go routines
	waitGroup := sync.WaitGroup{}

	createCategories(&waitGroup, categories, outputPath, configData, contentData, baseHtmlContent)
	createContent(&waitGroup, outputPath, configData, contentData, baseHtmlContent)

	// wait until all go routines have finished
	waitGroup.Wait()
}
コード例 #18
0
ファイル: smog.go プロジェクト: rubiojr/smog
func createDir() settings {
	u := make(url.Values)
	resp, err := http.PostForm(tahoe_url+"uri?t=mkdir&format=mdmf", u)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	var s settings
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	s.URI = string(body)
	err = os.Mkdir(".smog/", 0744)
	if err != nil {
		log.Fatal(err)
	}
	f, err := os.OpenFile(".smog/settings", os.O_CREATE|os.O_WRONLY, 0777)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	out, err := json.Marshal(s)
	f.Write(out)
	os.Mkdir("./restored", 0777)
	return s
}
コード例 #19
0
ファイル: restore_test.go プロジェクト: AlexisBruemmer/juju
func (r *RestoreSuite) createTestFiles(c *gc.C) {
	tarDirE := path.Join(r.cwd, "TarDirectoryEmpty")
	err := os.Mkdir(tarDirE, os.FileMode(0755))
	c.Check(err, jc.ErrorIsNil)

	tarDirP := path.Join(r.cwd, "TarDirectoryPopulated")
	err = os.Mkdir(tarDirP, os.FileMode(0755))
	c.Check(err, jc.ErrorIsNil)

	tarSubFile1 := path.Join(tarDirP, "TarSubFile1")
	tarSubFile1Handle, err := os.Create(tarSubFile1)
	c.Check(err, jc.ErrorIsNil)
	tarSubFile1Handle.WriteString("TarSubFile1")
	tarSubFile1Handle.Close()

	tarSubDir := path.Join(tarDirP, "TarDirectoryPopulatedSubDirectory")
	err = os.Mkdir(tarSubDir, os.FileMode(0755))
	c.Check(err, jc.ErrorIsNil)

	tarFile1 := path.Join(r.cwd, "TarFile1")
	tarFile1Handle, err := os.Create(tarFile1)
	c.Check(err, jc.ErrorIsNil)
	tarFile1Handle.WriteString("TarFile1")
	tarFile1Handle.Close()

	tarFile2 := path.Join(r.cwd, "TarFile2")
	tarFile2Handle, err := os.Create(tarFile2)
	c.Check(err, jc.ErrorIsNil)
	tarFile2Handle.WriteString("TarFile2")
	tarFile2Handle.Close()
	r.testFiles = []string{tarDirE, tarDirP, tarFile1, tarFile2}
}
コード例 #20
0
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd := fuse.MakeTempDir()
	err := os.Mkdir(wd+"/mount", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/store", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)
	WriteFile(wd+"/ro/file1", "file1")
	WriteFile(wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)
	state, conn, err := fuse.MountFileSystem(wd+"/mount", fs, &testAOpts.FileSystemOptions)
	CheckSuccess(err)
	state.Debug = true
	conn.Debug = true
	go state.Loop(false)

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
コード例 #21
0
ファイル: models.go プロジェクト: flying99999/beeweb
func initBlogMap() {
	os.Mkdir("blog", os.ModePerm)
	langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
	for _, l := range langs {
		os.Mkdir("blog/"+l, os.ModePerm)
	}

	if !utils.FileExists("conf/blogTree.json") {
		beego.Error("models.initBlogMap -> conf/blogTree.json does not exist")
		return
	}

	f, err := os.Open("conf/blogTree.json")
	if err != nil {
		beego.Error("models.initBlogMap -> load data:", err.Error())
		return
	}
	defer f.Close()

	d := json.NewDecoder(f)
	err = d.Decode(&blogTree)
	if err != nil {
		beego.Error("models.initBlogMap -> decode data:", err.Error())
		return
	}

	blogLock.Lock()
	defer blogLock.Unlock()

	blogMap = make(map[string]*docFile)
	for _, v := range blogTree.Tree {
		blogMap[v.Path] = getFile("blog/" + v.Path)
	}
}
コード例 #22
0
func initState(stableStoreBaseDir string, logBaseDir string, raftLogDir string) {
	err := os.RemoveAll(stableStoreBaseDir)
	if err != nil {
		panic("Cannot remove " + stableStoreBaseDir)
	}

	err = os.RemoveAll(logBaseDir)

	if err != nil {
		panic("Cannot remove " + logBaseDir)
	}

	err = os.RemoveAll(raftLogDir)
	if err != nil {
		panic("Cannot remove " + raftLogDir)
	}

	err = os.Mkdir(stableStoreBaseDir, os.ModeDir|0764)
	if err != nil {
		panic("Cannot create " + stableStoreBaseDir + "." + err.Error())
	}

	err = os.Mkdir(logBaseDir, os.ModeDir|0764)
	if err != nil {
		panic("Cannot create " + logBaseDir + "." + err.Error())
	}

	err = os.Mkdir(raftLogDir, os.ModeDir|0764)
	if err != nil {
		panic("Cannot create " + raftLogDir + "." + err.Error())
	}
}
コード例 #23
0
ファイル: autounion_test.go プロジェクト: y-okubo/go-fuse
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	err = os.Mkdir(wd+"/store", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	os.Mkdir(wd+"/ro", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}
	WriteFile(t, wd+"/ro/file1", "file1")
	WriteFile(t, wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)

	nfs := pathfs.NewPathNodeFs(fs, nil)
	state, _, err := nodefs.MountRoot(wd+"/mnt", nfs.Root(), &testAOpts.Options)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	fs.SetDebug(VerboseTest())
	go state.Serve()

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
コード例 #24
0
ファイル: memnode_test.go プロジェクト: taruti/go-fuse
func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) {
	tmp, err := ioutil.TempDir("", "go-fuse")
	CheckSuccess(err)
	back := tmp + "/backing"
	os.Mkdir(back, 0700)
	fs = NewMemNodeFs(back)
	mnt := tmp + "/mnt"
	os.Mkdir(mnt, 0700)

	connector := NewFileSystemConnector(fs,
		&FileSystemOptions{
			EntryTimeout:    testTtl,
			AttrTimeout:     testTtl,
			NegativeTimeout: 0.0,
		})
	connector.Debug = VerboseTest()
	state := NewMountState(connector)
	state.Mount(mnt, nil)

	//me.state.Debug = false
	state.Debug = VerboseTest()

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

}
コード例 #25
0
ファイル: cache_test.go プロジェクト: jasonmoo/go-fuse
func setupCacheTest(t *testing.T) (string, *PathNodeFs, func()) {
	dir, err := ioutil.TempDir("", "go-fuse-cachetest")
	if err != nil {
		t.Fatalf("TempDir failed: %v", err)
	}
	os.Mkdir(dir+"/mnt", 0755)
	os.Mkdir(dir+"/orig", 0755)

	fs := &cacheFs{
		LoopbackFileSystem: NewLoopbackFileSystem(dir + "/orig"),
	}
	pfs := NewPathNodeFs(fs, nil)
	state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs, nil)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	state.Debug = VerboseTest()
	conn.Debug = VerboseTest()
	pfs.Debug = VerboseTest()
	go state.Loop()

	return dir, pfs, func() {
		err := state.Unmount()
		if err == nil {
			os.RemoveAll(dir)
		}
	}
}
コード例 #26
0
ファイル: mc.go プロジェクト: rzh/utils
func initRunID(run string) string {
	if run == "" {
		fmt.Println("Please specify a run ID with -run!")
		os.Exit(1)
	}

	// check whether ./run exists, if not create it
	has_reports_folder, _ := exists("./" + report_folder + test)
	if !has_reports_folder {
		// create ./runs
		os.Mkdir("./"+report_folder+test, os.ModePerm)
	}

	// first make sure "./runs/run_id" folder does not exist
	run_dir := joinstr("./"+report_folder+test+"/", run, "")
	has_run_dir, _ := exists(run_dir)

	if has_run_dir {
		log.Fatal("the run_id ", run, " already exists!")
	}

	// then create the folder
	err := os.Mkdir(run_dir, os.ModePerm)
	if err != nil {
		log.Println("Failed to create ", run_dir)
	}

	return run_dir
}
コード例 #27
0
ファイル: attach.go プロジェクト: nangong92t/go_src
// 根据文件名生成文件路径, 如果文件路径不存在并创建
func (m *Attach) MakeFolderPath(rootPath string, fileName string) (string, string) {
	secs := time.Now().Unix()

	h := md5.New()
	h.Write([]byte(fileName + fmt.Sprintf("%s", secs)))
	fileName = fmt.Sprintf("%s", hex.EncodeToString(h.Sum(nil)))
	pathstrs := []rune(fileName)
	f1, f2, f3 := string(pathstrs[0]), string(pathstrs[1:4]), string(pathstrs[5:10])

	tPath := rootPath + "/" + f1
	isExists, _ := m.IsFolder(tPath)
	if !isExists {
		os.Mkdir(tPath, 0755)
	}

	tPath = tPath + "/" + f2
	isExists, _ = m.IsFolder(tPath)
	if !isExists {
		os.Mkdir(tPath, 0755)
	}

	tPath = tPath + "/" + f3
	isExists, _ = m.IsFolder(tPath)
	if !isExists {
		os.Mkdir(tPath, 0755)
	}

	path := f1 + "/" + f2 + "/" + f3

	return path, fileName
}
コード例 #28
0
ファイル: micro.go プロジェクト: Calinou/micro
// InitConfigDir finds the configuration directory for micro according to the XDG spec.
// If no directory is found, it creates one.
func InitConfigDir() {
	xdgHome := os.Getenv("XDG_CONFIG_HOME")
	if xdgHome == "" {
		// The user has not set $XDG_CONFIG_HOME so we should act like it was set to ~/.config
		home, err := homedir.Dir()
		if err != nil {
			TermMessage("Error finding your home directory\nCan't load config files")
			return
		}
		xdgHome = home + "/.config"
	}
	configDir = xdgHome + "/micro"

	if _, err := os.Stat(xdgHome); os.IsNotExist(err) {
		// If the xdgHome doesn't exist we should create it
		err = os.Mkdir(xdgHome, os.ModePerm)
		if err != nil {
			TermMessage("Error creating XDG_CONFIG_HOME directory: " + err.Error())
		}
	}

	if _, err := os.Stat(configDir); os.IsNotExist(err) {
		// If the micro specific config directory doesn't exist we should create that too
		err = os.Mkdir(configDir, os.ModePerm)
		if err != nil {
			TermMessage("Error creating configuration directory: " + err.Error())
		}
	}
}
コード例 #29
0
ファイル: autounion_test.go プロジェクト: crazy2be/go-fuse
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/store", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)
	WriteFile(wd+"/ro/file1", "file1")
	WriteFile(wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)
	state, conn, err := fuse.MountPathFileSystem(wd+"/mnt", fs, &testAOpts.FileSystemOptions)
	CheckSuccess(err)
	state.Debug = fuse.VerboseTest()
	conn.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
コード例 #30
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Please give me the url of the musican.")
		return
	}
	//body := get("http://site.douban.com/Ceekay/")
	body := get(os.Args[1])
	os.Mkdir("music", 0755)

	re0 := regexp.MustCompile(`(?s)<div class="sp-nav">.*?<div class="sp-logo">.*?<img.*?alt="(.*?)"`)
	matches0 := re0.FindStringSubmatch(body)
	name := matches0[1]
	fmt.Println(name)
	os.Mkdir("music/"+name, 0755)

	re := regexp.MustCompile(`(?s)<div class="mod" id="playlist-(\d+)">.*?<span>(.*?)</span>`)
	matches := re.FindAllStringSubmatch(body, -1)
	for _, m := range matches {
		fmt.Println("\t" + m[2])
		os.Mkdir("music/"+name+"/"+m[2], 0755)
		re2 := regexp.MustCompile(`(?s)var widget = PlaylistWidget.findOrCreate\(` + m[1] + `\),.*?song_records = .*?is_login = false;`)
		match := re2.FindString(body)
		re3 := regexp.MustCompile(`(?s){"name":"(.*?)",.*?"rawUrl":"(.*?)",`)
		matches3 := re3.FindAllStringSubmatch(match, -1)
		for _, m3 := range matches3 {
			fmt.Printf("\t\t%s %s\n", m3[1], m3[2])
			filename := "music/" + name + "/" + m[2] + "/" + m3[1] + ".mp3"
			if !fileExist(filename) {
				getstore(strings.Replace(m3[2], "\\", "", -1), filename)

				tagIt(filename, m3[1], m[2], name, "hippop")
			}
		}
	}
}