func MakeDirectory(apiClient pfs.ApiClient, repoName string, commitID string, path string) (retErr error) { putFileClient, err := apiClient.PutFile(context.Background()) if err != nil { return err } defer func() { if _, err := putFileClient.CloseAndRecv(); err != nil && retErr != nil { retErr = err } }() return putFileClient.Send( &pfs.PutFileRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, FileType: pfs.FileType_FILE_TYPE_DIR, }, ) }
func GetFile(apiClient pfs.ApiClient, repositoryName string, commitID string, path string, offset int64, size int64, writer io.Writer) error { apiGetFileClient, err := apiClient.GetFile( context.Background(), &pfs.GetFileRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, OffsetBytes: offset, SizeBytes: size, }, ) if err != nil { return err } if err := protostream.WriteFromStreamingBytesClient(apiGetFileClient, writer); err != nil { return err } return nil }
func InspectServer(apiClient pfs.ApiClient, serverID string) (*pfs.ServerInfo, error) { return apiClient.InspectServer( context.Background(), &pfs.InspectServerRequest{ Server: &pfs.Server{ Id: serverID, }, }, ) }
func ListCommits(apiClient pfs.ApiClient, repositoryName string) (*pfs.CommitInfos, error) { return apiClient.ListCommits( context.Background(), &pfs.ListCommitsRequest{ Repository: &pfs.Repository{ Name: repositoryName, }, }, ) }
func ListRepo(apiClient pfs.ApiClient) ([]*pfs.RepoInfo, error) { repoInfos, err := apiClient.ListRepo( context.Background(), &pfs.ListRepoRequest{}, ) if err != nil { return nil, err } return repoInfos.RepoInfo, nil }
func ListServer(apiClient pfs.ApiClient) ([]*pfs.ServerInfo, error) { serverInfos, err := apiClient.ListServer( context.Background(), &pfs.ListServerRequest{}, ) if err != nil { return nil, err } return serverInfos.ServerInfo, nil }
func InitRepository(apiClient pfs.ApiClient, repositoryName string) error { _, err := apiClient.InitRepository( context.Background(), &pfs.InitRepositoryRequest{ Repository: &pfs.Repository{ Name: repositoryName, }, }, ) return err }
func DeleteRepo(apiClient pfs.ApiClient, repoName string) error { _, err := apiClient.DeleteRepo( context.Background(), &pfs.DeleteRepoRequest{ Repo: &pfs.Repo{ Name: repoName, }, }, ) return err }
func Branch(apiClient pfs.ApiClient, repositoryName string, commitID string) (*pfs.Commit, error) { return apiClient.Branch( context.Background(), &pfs.BranchRequest{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, }, ) }
func GetCommitInfo(apiClient pfs.ApiClient, repositoryName string, commitID string) (*pfs.GetCommitInfoResponse, error) { return apiClient.GetCommitInfo( context.Background(), &pfs.GetCommitInfoRequest{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, }, ) }
func Write(apiClient pfs.ApiClient, repositoryName string, commitID string) error { _, err := apiClient.Write( context.Background(), &pfs.WriteRequest{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, }, ) return err }
func FinishCommit(apiClient pfs.ApiClient, repoName string, commitID string) error { _, err := apiClient.FinishCommit( context.Background(), &pfs.FinishCommitRequest{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, }, ) return err }
func InspectBlock(apiClient pfs.ApiClient, hash string) (*pfs.BlockInfo, error) { blockInfo, err := apiClient.InspectBlock( context.Background(), &pfs.InspectBlockRequest{ Block: &pfs.Block{ Hash: hash, }, }, ) if err != nil { return nil, err } return blockInfo, nil }
func InspectRepo(apiClient pfs.ApiClient, repoName string) (*pfs.RepoInfo, error) { repoInfo, err := apiClient.InspectRepo( context.Background(), &pfs.InspectRepoRequest{ Repo: &pfs.Repo{ Name: repoName, }, }, ) if err != nil { return nil, err } return repoInfo, nil }
func ListCommit(apiClient pfs.ApiClient, repoName string) ([]*pfs.CommitInfo, error) { commitInfos, err := apiClient.ListCommit( context.Background(), &pfs.ListCommitRequest{ Repo: &pfs.Repo{ Name: repoName, }, }, ) if err != nil { return nil, err } return commitInfos.CommitInfo, nil }
func ListBlock(apiClient pfs.ApiClient, shard uint64, modulus uint64) ([]*pfs.BlockInfo, error) { blockInfos, err := apiClient.ListBlock( context.Background(), &pfs.ListBlockRequest{ Shard: &pfs.Shard{ Number: shard, Modulo: modulus, }, }, ) if err != nil { return nil, err } return blockInfos.BlockInfo, nil }
func GetFileInfo(apiClient pfs.ApiClient, repositoryName string, commitID string, path string) (*pfs.FileInfo, error) { return apiClient.GetFileInfo( context.Background(), &pfs.GetFileInfoRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, }, ) }
func StartCommit(apiClient pfs.ApiClient, repoName string, parentCommit string) (*pfs.Commit, error) { commit, err := apiClient.StartCommit( context.Background(), &pfs.StartCommitRequest{ Parent: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: parentCommit, }, }, ) if err != nil { return nil, err } return commit, nil }
func GetBlock(apiClient pfs.ApiClient, hash string, writer io.Writer) error { apiGetBlockClient, err := apiClient.GetBlock( context.Background(), &pfs.GetBlockRequest{ Block: &pfs.Block{ Hash: hash, }, }, ) if err != nil { return err } if err := protostream.WriteFromStreamingBytesClient(apiGetBlockClient, writer); err != nil { return err } return nil }
func DeleteFile(apiClient pfs.ApiClient, repoName string, commitID string, path string) error { _, err := apiClient.DeleteFile( context.Background(), &pfs.DeleteFileRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, }, ) return err }
func InspectCommit(apiClient pfs.ApiClient, repoName string, commitID string) (*pfs.CommitInfo, error) { commitInfo, err := apiClient.InspectCommit( context.Background(), &pfs.InspectCommitRequest{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, }, ) if err != nil { return nil, err } return commitInfo, nil }
func MakeDirectory(apiClient pfs.ApiClient, repositoryName string, commitID string, path string) error { _, err := apiClient.MakeDirectory( context.Background(), &pfs.MakeDirectoryRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, }, ) return err }
func PutFile(apiClient pfs.ApiClient, repoName string, commitID string, path string, offset int64, reader io.Reader) (_ int, retErr error) { putFileClient, err := apiClient.PutFile(context.Background()) if err != nil { return 0, err } defer func() { if _, err := putFileClient.CloseAndRecv(); err != nil && retErr != nil { retErr = err } }() request := pfs.PutFileRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, FileType: pfs.FileType_FILE_TYPE_REGULAR, OffsetBytes: offset, } var size int for { value := make([]byte, chunkSize) iSize, err := reader.Read(value) request.Value = value[0:iSize] if err != nil { if err == io.EOF { break } return 0, err } size += iSize protolog.Printf("pfsutil.PutFile Send(%+v)", request) if err := putFileClient.Send(&request); err != nil { return 0, err } } if err != nil && err != io.EOF { return 0, err } return size, err }
func ListFiles(apiClient pfs.ApiClient, repositoryName string, commitID string, path string, shardNum int, shardModulo int) (*pfs.ListFilesResponse, error) { return apiClient.ListFiles( context.Background(), &pfs.ListFilesRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, Shard: &pfs.Shard{ Number: uint64(shardNum), Modulo: uint64(shardModulo), }, }, ) }
func InspectFile(apiClient pfs.ApiClient, repoName string, commitID string, path string) (*pfs.FileInfo, error) { fileInfo, err := apiClient.InspectFile( context.Background(), &pfs.InspectFileRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, }, ) if err != nil { return nil, err } return fileInfo, nil }
func ListFiles(apiClient pfs.ApiClient, repositoryName string, commitID string, path string, shard uint64, modulus uint64) (*pfs.FileInfos, error) { return apiClient.ListFiles( context.Background(), &pfs.ListFilesRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, Shard: &pfs.Shard{ Number: shard, Modulo: modulus, }, }, ) }
func PutBlock(apiClient pfs.ApiClient, repoName string, commitID string, path string, reader io.Reader) (*pfs.Block, error) { value, err := ioutil.ReadAll(reader) if err != nil { return nil, err } return apiClient.PutBlock( context.Background(), &pfs.PutBlockRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, Value: value, }, ) }
func PutFile(apiClient pfs.ApiClient, repositoryName string, commitID string, path string, reader io.Reader) error { value, err := ioutil.ReadAll(reader) if err != nil { return err } _, err = apiClient.PutFile( context.Background(), &pfs.PutFileRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, Value: value, }, ) return err }
func PutFile(apiClient pfs.ApiClient, repositoryName string, commitID string, path string, offset int64, reader io.Reader) (int64, error) { value, err := ioutil.ReadAll(reader) if err != nil { return 0, err } _, err = apiClient.PutFile( context.Background(), &pfs.PutFileRequest{ Path: &pfs.Path{ Commit: &pfs.Commit{ Repository: &pfs.Repository{ Name: repositoryName, }, Id: commitID, }, Path: path, }, OffsetBytes: offset, Value: value, }, ) return int64(len(value)), err }
func ListChange(apiClient pfs.ApiClient, repoName string, commitID string, path string, shard uint64, modulus uint64) ([]*pfs.Change, error) { changes, err := apiClient.ListChange( context.Background(), &pfs.ListChangeRequest{ File: &pfs.File{ Commit: &pfs.Commit{ Repo: &pfs.Repo{ Name: repoName, }, Id: commitID, }, Path: path, }, Shard: &pfs.Shard{ Number: shard, Modulo: modulus, }, }, ) if err != nil { return nil, err } return changes.Change, nil }