本文整理汇总了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")
}
示例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
}
示例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
}
示例4: expadGoPath
func expadGoPath(path string) (r string) {
r = path
if filepath.VolumeName(path) == "" {
r = filepath.Join(gGoPath, path)
}
return
}
示例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()
}
示例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)
}
示例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):])
}
示例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) != ""
}
示例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
}
示例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()
})
}
示例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)
}
}
示例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
}
示例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
}
示例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 == "/"
}
示例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)
}
}