示例#1
0
func TestGetMountPointFromPath(t *testing.T) {
	tempfile, err := ioutil.TempFile("", "platform_test")
	require.Nil(t, err)
	mountpoint, err := platform.GetMountPointFromPath(tempfile.Name())
	assert.Nil(t, err)
	if runtime.GOOS == "linux" || runtime.GOOS == "darwin" ||
		runtime.GOOS == "unix" || runtime.GOOS == "bsd" {
		assert.Equal(t, "/", mountpoint)
	} else if runtime.GOOS == "windows" {
		assert.Equal(t, tempfile.Name(), mountpoint)
	}
}
示例#2
0
// Returns a Volume object with info about the volume at the specified
// mount point. The mount point should be the path to a disk or partition.
// For example, "/", "/mnt/data", etc.
func (service *VolumeService) getVolume(path string) *models.Volume {
	mountpoint, err := platform.GetMountPointFromPath(path)
	if err != nil {
		mountpoint = "/"
		service.logger.Error("Cannot determine mountpoint of file '%s': %v",
			path, err)
	}
	if _, keyExists := service.volumes[mountpoint]; !keyExists {
		service.volumes[mountpoint] = models.NewVolume(mountpoint)
	}
	return service.volumes[mountpoint]
}