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


Golang filepath.VolumeName函数代码示例

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


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

示例1: main

func main() {
	userdata, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}

	wd, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	savedir := userdata.HomeDir
	scandir := filepath.VolumeName(wd)
	if filepath.VolumeName(savedir) != scandir {
		savedir = scandir
	}
	savedir += string(filepath.Separator)
	scandir += string(filepath.Separator)

	log.Println("Scanning Volume:", scandir)
	log.Println("Saving Index to:", savedir)

	data := index(scandir)

	log.Println("Encoding Index")
	save(savedir+"index.fed", data)
	log.Println("Finished")
}
开发者ID:hirsch,项目名称:fedd,代码行数:28,代码来源:fedd.go

示例2: MakeFileURL

// MakeFileURL returns a proper file URL for the given path/directory
func MakeFileURL(in string) string {
	var volumeName string
	if strings.HasPrefix(in, "file://") {
		volumeName = filepath.VolumeName(strings.TrimPrefix(in, "file://"))
	} else {
		volumeName = filepath.VolumeName(in)
	}

	if volumeName != "" {
		// Strip colon
		volumeName = strings.TrimSuffix(volumeName, ":")

		// Do not apply function twice
		if strings.HasPrefix(in, "file://\\\\localhost\\") {
			return in
		}

		in = filepath.ToSlash(in)
		prefix := "file://\\\\localhost\\" + volumeName + "$"
		if strings.HasPrefix(in, volumeName) {
			return prefix + strings.TrimPrefix(in, volumeName+":")
		}
		if strings.HasPrefix(in, "file://"+volumeName) {
			return prefix + strings.TrimPrefix(in, "file://"+volumeName+":")
		}
	}

	return in
}
开发者ID:sinzui,项目名称:utils,代码行数:30,代码来源:file_windows.go

示例3: CommonRoot

func CommonRoot(pa, pb string) string {
	if pa == "" || pb == "" {
		return ""
	}

	pac := filepath.Clean(pa)
	pbc := filepath.Clean(pb)

	va := filepath.VolumeName(pac)
	vb := filepath.VolumeName(pbc)

	if va != vb {
		return ""
	}

	sa := pac[len(va):]
	sb := pbc[len(vb):]

	na := len(sa)
	nb := len(sb)

	var cursor, lastSep int
	lastSep = -1

	for {
		if cursor < na && cursor < nb && sa[cursor] == sb[cursor] {
			if sa[cursor] == filepath.Separator {
				lastSep = cursor
			}
			cursor++
		} else {
			break
		}
	}

	if cursor == na && na == nb {
		return pac
	}

	if cursor == na && na < nb && sb[na] == filepath.Separator {
		return pac
	}

	if cursor == nb && nb < na && sa[nb] == filepath.Separator {
		return pbc
	}

	if lastSep == -1 {
		return va + string(filepath.Separator)
	}

	res := pac[0 : len(va)+lastSep]

	if res == "" && filepath.Separator == '/' {
		return "/"
	}

	return res
}
开发者ID:uwedeportivo,项目名称:romba,代码行数:59,代码来源:worker.go

示例4: expadGoPath

func expadGoPath(path string) (r string) {
	r = path
	if filepath.VolumeName(path) == "" {
		r = filepath.Join(gGoPath, path)
	}
	return
}
开发者ID:vipally,项目名称:gogp,代码行数:7,代码来源:gpg.go

示例5: withConfigFixture

func withConfigFixture(t *testing.T, name string, callback func()) {
	oldHome := os.Getenv("HOME")
	oldHomePath := os.Getenv("HOMEPATH")
	oldHomeDrive := os.Getenv("HOMEDRIVE")
	defer func() {
		os.Setenv("HOMEDRIVE", oldHomeDrive)
		os.Setenv("HOMEPATH", oldHomePath)
		os.Setenv("HOME", oldHome)
	}()

	defer func() {
		singleton = nil
	}()

	cwd, err := os.Getwd()
	assert.NoError(t, err)

	fixturePath := filepath.Join(cwd, fmt.Sprintf("../../fixtures/config/%s", name))
	os.Setenv("HOME", fixturePath)

	volumeName := filepath.VolumeName(fixturePath)
	if volumeName != "" {
		relativePath := strings.Replace(fixturePath, volumeName, "", 1)

		os.Setenv("HOMEPATH", relativePath)
		os.Setenv("HOMEDRIVE", volumeName)
	}

	callback()
}
开发者ID:nsnt,项目名称:cli,代码行数:30,代码来源:repository_test.go

示例6: TestEvalSymlinksCanonicalNamesWith8dot3Disabled

// This test assumes registry state of NtfsDisable8dot3NameCreation is 2,
// the default (Volume level setting).
func TestEvalSymlinksCanonicalNamesWith8dot3Disabled(t *testing.T) {
	if !*runFSModifyTests {
		t.Skip("skipping test that modifies file system setting; enable with -run_fs_modify_tests")
	}
	tempVol := filepath.VolumeName(os.TempDir())
	if len(tempVol) != 2 {
		t.Fatalf("unexpected temp volume name %q", tempVol)
	}

	err := checkVolume8dot3Setting(tempVol, true)
	if err != nil {
		t.Fatal(err)
	}
	err = setVolume8dot3Setting(tempVol, false)
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err := setVolume8dot3Setting(tempVol, true)
		if err != nil {
			t.Fatal(err)
		}
		err = checkVolume8dot3Setting(tempVol, true)
		if err != nil {
			t.Fatal(err)
		}
	}()
	err = checkVolume8dot3Setting(tempVol, false)
	if err != nil {
		t.Fatal(err)
	}
	TestEvalSymlinksCanonicalNames(t)
}
开发者ID:Xiahl1990,项目名称:go,代码行数:35,代码来源:path_windows_test.go

示例7: EnsureBaseDir

// EnsureBaseDir ensures that path is always prefixed by baseDir,
// allowing for the fact that path might have a Window drive letter in
// it.
func EnsureBaseDir(baseDir, path string) string {
	if baseDir == "" {
		return path
	}
	volume := filepath.VolumeName(path)
	return filepath.Join(baseDir, path[len(volume):])
}
开发者ID:kat-co,项目名称:utils,代码行数:10,代码来源:file.go

示例8: isLocalPath

// isLocalPath returns whether the given path is local (/foo ./foo ../foo . ..)
// Windows paths that starts with drive letter (c:\foo c:foo) are considered local.
func isLocalPath(s string) bool {
	const sep = string(filepath.Separator)
	return s == "." || s == ".." ||
		filepath.HasPrefix(s, sep) ||
		filepath.HasPrefix(s, "."+sep) || filepath.HasPrefix(s, ".."+sep) ||
		filepath.VolumeName(s) != ""
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:9,代码来源:path.go

示例9: EvaluateTargets

func EvaluateTargets(t []string) string {

	h := syscall.MustLoadDLL("kernel32.dll")
	c := h.MustFindProc("GetDiskFreeSpaceExW")

	var maxFreeBytes uint64
	var bestTarget string

	for _, p := range t {
		var freeBytes uint64

		vol := filepath.VolumeName(p)

		ptr1 := unsafe.Pointer(syscall.StringToUTF16Ptr(vol))
		ptr2 := unsafe.Pointer(&freeBytes)

		c.Call(
			uintptr(ptr1),
			uintptr(ptr2),
			uintptr(0),
			uintptr(0),
		)

		if freeBytes > maxFreeBytes {
			maxFreeBytes = freeBytes
			bestTarget = p
		}
	}
	return bestTarget
}
开发者ID:serverhorror,项目名称:mvln,代码行数:30,代码来源:winpath.go

示例10: withFakeHome

func withFakeHome(t *testing.T, callback func()) {
	oldHome := os.Getenv("HOME")
	oldHomePath := os.Getenv("HOMEPATH")
	oldHomeDrive := os.Getenv("HOMEDRIVE")
	defer func() {
		os.Setenv("HOMEDRIVE", oldHomeDrive)
		os.Setenv("HOMEPATH", oldHomePath)
		os.Setenv("HOME", oldHome)
	}()

	defer func() {
		NewConfigurationDiskRepository().Delete()
	}()

	fileutils.TempDir("test-config", func(dir string, err error) {
		os.Setenv("HOME", dir)

		volumeName := filepath.VolumeName(dir)
		if volumeName != "" {
			relativePath := strings.Replace(dir, volumeName, "", 1)

			os.Setenv("HOMEPATH", relativePath)
			os.Setenv("HOMEDRIVE", volumeName)
		}

		callback()
	})
}
开发者ID:nsnt,项目名称:cli,代码行数:28,代码来源:repository_test.go

示例11: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	dir, err := os.Getwd()
	if err != nil {
		fatal.Fatalln(err)
	}

	// "To flush all open files on a volume, call FlushFileBuffers with a handle to the volume.
	// The caller must have administrative privileges. For more information, see Running with Special Privileges."
	// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aspx
	fp := filepath.VolumeName(dir)
	file, err := os.Open(fp)
	if err != nil {
		fatal.Fatalln(err)
	}

	err = syscall.Fsync(syscall.Handle(file.Fd()))
	if err != nil {
		fatal.Fatalln(err)
	}
}
开发者ID:patrickToca,项目名称:go-coreutils,代码行数:26,代码来源:sync_windows.go

示例12: resolveDestination

func (u *Untar) resolveDestination(name string) (string, error) {
	pathParts := strings.Split(name, string(os.PathSeparator))

	// walk the path parts to find at what point the resolvedLinks deviates
	i := 0
	for i, _ = range pathParts {
		if (i < len(u.resolvedLinks)) && pathParts[i] == u.resolvedLinks[i].src {
			continue
		}
		break
	}

	// truncate the slice to only the matching pieces
	u.resolvedLinks = u.resolvedLinks[0:i]

	// special handling for an empty array...
	// normally it begins with the previous dest, but if it is empty we need to
	// start with resolving the first path piece
	if len(u.resolvedLinks) == 0 {
		p := pathParts[i]

		if p == "" {
			// Path shouldn't start empty; resolve it from the root.
			if runtime.GOOS == "windows" {
				p = filepath.VolumeName(name)
			} else {
				p = string(os.PathSeparator)
			}
		}

		dst, err := u.convertToDestination(p)
		if err != nil {
			return "", err
		}

		u.resolvedLinks = append(
			u.resolvedLinks,
			resolvedLink{src: pathParts[i], dst: dst})
		i++
	}

	// build up the resolution for the rest of the pieces
	for j := i; j < len(pathParts); j++ {
		testPath := filepath.Join(
			u.resolvedLinks[len(u.resolvedLinks)-1].dst,
			pathParts[j])

		dst, err := u.convertToDestination(testPath)
		if err != nil {
			return "", err
		}

		u.resolvedLinks = append(
			u.resolvedLinks,
			resolvedLink{src: pathParts[j], dst: dst})
	}

	// the last entry is the full resolution
	return u.resolvedLinks[len(u.resolvedLinks)-1].dst, nil
}
开发者ID:wallyqs,项目名称:util,代码行数:60,代码来源:untar.go

示例13: Cleanname

func Cleanname(name string) string {
	name = filepath.Clean(name)

	if len(Flagd) > 0 && filepath.VolumeName(name) == "" {
		name = filepath.Clean(Flagd) + string(os.PathSeparator) + name
	}

	return name
}
开发者ID:CodyGuo,项目名称:gobase,代码行数:9,代码来源:cleanname.go

示例14: isRoot

// isRoot returns true iff a path is a root.
// On Unix: "/".
// On Windows: "C:\", "D:\", ...
func isRoot(p string) bool {
	p = filepath.Clean(p)
	volume := filepath.VolumeName(p)

	p = strings.TrimPrefix(p, volume)
	p = filepath.ToSlash(p)

	return p == "/"
}
开发者ID:roger2000hk,项目名称:godep,代码行数:12,代码来源:go.go

示例15: TestVolumeName

func (s windowsSuite) TestVolumeName(c *gc.C) {
	volumeName := s.renderer.VolumeName(s.path)

	c.Check(volumeName, gc.Equals, "c:")
	if s.matchesRuntime() {
		goresult := gofilepath.VolumeName(s.path)
		c.Check(volumeName, gc.Equals, goresult)
	}
}
开发者ID:sinzui,项目名称:utils,代码行数:9,代码来源:win_test.go


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