本文整理汇总了Golang中github.com/pachyderm/pachyderm/src/pfs/pfsutil.ListFile函数的典型用法代码示例。如果您正苦于以下问题:Golang ListFile函数的具体用法?Golang ListFile怎么用?Golang ListFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListFile函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readFiles
func (d *directory) readFiles(ctx context.Context) ([]fuse.Dirent, error) {
fileInfos, err := pfsutil.ListFile(
d.fs.apiClient,
d.File.Commit.Repo.Name,
d.File.Commit.Id,
d.File.Path,
d.fs.getFromCommitID(d.File.Commit.Repo.Name),
d.Shard,
)
if err != nil {
return nil, err
}
var result []fuse.Dirent
for _, fileInfo := range fileInfos {
shortPath := strings.TrimPrefix(fileInfo.File.Path, d.File.Path)
switch fileInfo.FileType {
case pfs.FileType_FILE_TYPE_REGULAR:
result = append(result, fuse.Dirent{Name: shortPath, Type: fuse.DT_File})
case pfs.FileType_FILE_TYPE_DIR:
result = append(result, fuse.Dirent{Name: shortPath, Type: fuse.DT_Dir})
default:
continue
}
}
return result, nil
}
示例2: ReadDirAll
func (d *directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
if d.commitID == "" {
return d.readCommits(ctx)
}
fileInfos, err := pfsutil.ListFile(d.fs.apiClient, d.fs.repositoryName, d.commitID, d.path, d.fs.shard, d.fs.modulus)
if err != nil {
return nil, err
}
result := make([]fuse.Dirent, 0, len(fileInfos))
for _, fileInfo := range fileInfos {
shortPath := strings.TrimPrefix(fileInfo.File.Path, d.path)
switch fileInfo.FileType {
case pfs.FileType_FILE_TYPE_REGULAR:
result = append(result, fuse.Dirent{Name: shortPath, Type: fuse.DT_File})
case pfs.FileType_FILE_TYPE_DIR:
result = append(result, fuse.Dirent{Name: shortPath, Type: fuse.DT_Dir})
default:
continue
}
}
return result, nil
}
示例3: testSimple
func testSimple(t *testing.T, apiClient pfs.APIClient, cluster Cluster) {
repoName := "testSimpleRepo"
err := pfsutil.CreateRepo(apiClient, repoName)
require.NoError(t, err)
commit, err := pfsutil.StartCommit(apiClient, repoName, "")
require.NoError(t, err)
require.NotNil(t, commit)
newCommitID := commit.Id
newCommitInfo, err := pfsutil.InspectCommit(apiClient, repoName, newCommitID)
require.NoError(t, err)
require.NotNil(t, newCommitInfo)
require.Equal(t, newCommitID, newCommitInfo.Commit.Id)
require.Equal(t, pfs.CommitType_COMMIT_TYPE_WRITE, newCommitInfo.CommitType)
require.Nil(t, newCommitInfo.ParentCommit)
commitInfos, err := pfsutil.ListCommit(apiClient, repoName)
require.NoError(t, err)
require.Equal(t, 1, len(commitInfos))
require.Equal(t, newCommitInfo.Commit, commitInfos[0].Commit)
err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/b")
require.NoError(t, err)
err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/c")
require.NoError(t, err)
err = pfsutil.MakeDirectory(apiClient, repoName, newCommitID, "a/d")
require.NoError(t, err)
doWrites(t, apiClient, repoName, newCommitID)
doBlockWrites(t, apiClient, repoName, newCommitID)
err = pfsutil.FinishCommit(apiClient, repoName, newCommitID)
require.NoError(t, err)
newCommitInfo, err = pfsutil.InspectCommit(apiClient, repoName, newCommitID)
require.NoError(t, err)
require.NotNil(t, newCommitInfo)
require.Equal(t, newCommitID, newCommitInfo.Commit.Id)
require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, newCommitInfo.CommitType)
require.Nil(t, newCommitInfo.ParentCommit)
checkWrites(t, apiClient, repoName, newCommitID)
checkBlockWrites(t, apiClient, repoName, newCommitID)
fileInfos, err := pfsutil.ListFile(apiClient, repoName, newCommitID, "a/b", &pfs.Shard{Number: 0, Modulus: 1})
require.NoError(t, err)
require.Equal(t, testSize, len(fileInfos))
fileInfos, err = pfsutil.ListFile(apiClient, repoName, newCommitID, "a/c", &pfs.Shard{Number: 0, Modulus: 1})
require.NoError(t, err)
require.Equal(t, testSize, len(fileInfos))
var fileInfos2 [7][]*pfs.FileInfo
var wg sync.WaitGroup
for i := 0; i < 7; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
fileInfos3, iErr := pfsutil.ListFile(apiClient, repoName, newCommitID, "a/b", &pfs.Shard{Number: uint64(i), Modulus: 7})
require.NoError(t, iErr)
fileInfos2[i] = fileInfos3
}()
}
wg.Wait()
count := 0
for i := 0; i < 7; i++ {
count += len(fileInfos2[i])
}
require.Equal(t, testSize, count)
}
示例4: Cmds
//.........这里部分代码省略.........
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2], shard())
if err != nil {
return err
}
if fileInfo == nil {
return fmt.Errorf("file %s not found", args[2])
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
pretty.PrintFileInfo(writer, fileInfo)
return writer.Flush()
}),
}
inspectFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from")
inspectFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards")
listFile := &cobra.Command{
Use: "list-file repo-name commit-id path/to/dir",
Short: "Return the files in a directory.",
Long: "Return the files in a directory.",
Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 2, Max: 3}, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
var path string
if len(args) == 3 {
path = args[2]
}
fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], path, shard())
if err != nil {
return err
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
for _, fileInfo := range fileInfos {
pretty.PrintFileInfo(writer, fileInfo)
}
return writer.Flush()
}),
}
listFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from")
listFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards")
deleteFile := &cobra.Command{
Use: "delete-file repo-name commit-id path/to/file",
Short: "Delete a file.",
Long: "Delete a file.",
Run: pkgcobra.RunFixedArgs(2, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2])
}),
}
listChange := &cobra.Command{
Use: "list-change repo-name commit-id path/to/dir",
Short: "Return the changes in a directory.",
Long: "Return the changes in a directory.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
示例5: do
//.........这里部分代码省略.........
Long: "Return the contents of a file.",
NumArgs: 3,
Run: func(cmd *cobra.Command, args []string) error {
return pfsutil.GetFile(apiClient, args[0], args[1], args[2], 0, math.MaxInt64, os.Stdout)
},
}.ToCobraCommand()
inspectFile := cobramainutil.Command{
Use: "inspect-file repo-name commit-id path/to/file",
Short: "Return info about a file.",
Long: "Return info about a file.",
NumArgs: 3,
Run: func(cmd *cobra.Command, args []string) error {
fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2])
if err != nil {
return err
}
if fileInfo == nil {
return fmt.Errorf("file %s not found", args[2])
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
pretty.PrintFileInfo(writer, fileInfo)
return writer.Flush()
},
}.ToCobraCommand()
listFile := cobramainutil.Command{
Use: "list-file repo-name commit-id path/to/dir",
Short: "Return the files in a directory.",
Long: "Return the files in a directory.",
NumArgs: 3,
Run: func(cmd *cobra.Command, args []string) error {
fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], args[2], uint64(shard), uint64(modulus))
if err != nil {
return err
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
for _, fileInfo := range fileInfos {
pretty.PrintFileInfo(writer, fileInfo)
}
return writer.Flush()
},
}.ToCobraCommand()
listFile.Flags().IntVarP(&shard, "shard", "s", 0, "shard to read from")
listFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards")
deleteFile := cobramainutil.Command{
Use: "delete-file repo-name commit-id path/to/file",
Short: "Delete a file.",
Long: "Delete a file.",
NumArgs: 2,
Run: func(cmd *cobra.Command, args []string) error {
return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2])
},
}.ToCobraCommand()
listChange := cobramainutil.Command{
Use: "list-change repo-name commit-id path/to/dir",
Short: "Return the changes in a directory.",
Long: "Return the changes in a directory.",
NumArgs: 3,
Run: func(cmd *cobra.Command, args []string) error {
changeInfos, err := pfsutil.ListChange(apiClient, args[0], args[1], args[2], uint64(shard), uint64(modulus))
if err != nil {
示例6: Cmds
//.........这里部分代码省略.........
Long: "Return info about a file.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2], "", shard())
if err != nil {
return err
}
if fileInfo == nil {
return fmt.Errorf("file %s not found", args[2])
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
pretty.PrintFileInfo(writer, fileInfo)
return writer.Flush()
}),
}
addShardFlags(inspectFile)
listFile := &cobra.Command{
Use: "list-file repo-name commit-id path/to/dir",
Short: "Return the files in a directory.",
Long: "Return the files in a directory.",
Run: pkgcobra.RunBoundedArgs(pkgcobra.Bounds{Min: 2, Max: 3}, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
var path string
if len(args) == 3 {
path = args[2]
}
fileInfos, err := pfsutil.ListFile(apiClient, args[0], args[1], path, "", shard())
if err != nil {
return err
}
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
pretty.PrintFileInfoHeader(writer)
for _, fileInfo := range fileInfos {
pretty.PrintFileInfo(writer, fileInfo)
}
return writer.Flush()
}),
}
addShardFlags(listFile)
deleteFile := &cobra.Command{
Use: "delete-file repo-name commit-id path/to/file",
Short: "Delete a file.",
Long: "Delete a file.",
Run: pkgcobra.RunFixedArgs(2, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
return pfsutil.DeleteFile(apiClient, args[0], args[1], args[2])
}),
}
var mountPoint string
mount := &cobra.Command{
Use: "mount [repo/commit:alias...]",
Short: "Mount pfs locally.",
Long: "Mount pfs locally.",
Run: pkgcobra.Run(func(args []string) error {
//lion.SetLevel(lion.LevelDebug)
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
mounter := fuse.NewMounter(address, apiClient)
return mounter.Mount(mountPoint, shard(), parseCommitMounts(args), nil)
}),
}
mount.Flags().StringVarP(&mountPoint, "mount-point", "p", "/pfs", "root of mounted filesystem")
addShardFlags(mount)
var result []*cobra.Command
result = append(result, repo)
result = append(result, createRepo)
result = append(result, inspectRepo)
result = append(result, listRepo)
result = append(result, deleteRepo)
result = append(result, commit)
result = append(result, startCommit)
result = append(result, finishCommit)
result = append(result, inspectCommit)
result = append(result, listCommit)
result = append(result, deleteCommit)
result = append(result, file)
result = append(result, putFile)
result = append(result, getFile)
result = append(result, inspectFile)
result = append(result, listFile)
result = append(result, deleteFile)
result = append(result, mount)
return result
}