Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): guard returning file entries with missing text #5580

Merged
merged 3 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions kythe/go/services/cli/command_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (

type lsCommand struct {
baseKytheCommand
lsURIs bool
filesOnly bool
dirsOnly bool
lsURIs bool
filesOnly bool
dirsOnly bool
includeMissing bool
}

func (lsCommand) Name() string { return "ls" }
Expand All @@ -42,6 +43,7 @@ func (c *lsCommand) SetFlags(flag *flag.FlagSet) {
flag.BoolVar(&c.lsURIs, "uris", false, "Display files/directories as Kythe URIs")
flag.BoolVar(&c.filesOnly, "files", false, "Display only files")
flag.BoolVar(&c.dirsOnly, "dirs", false, "Display only directories")
flag.BoolVar(&c.includeMissing, "include_files_missing_text", false, "Include files missing text")
}
func (c lsCommand) Run(ctx context.Context, flag *flag.FlagSet, api API) error {
if c.filesOnly && c.dirsOnly {
Expand Down Expand Up @@ -75,6 +77,8 @@ func (c lsCommand) Run(ctx context.Context, flag *flag.FlagSet, api API) error {
Corpus: corpus,
Root: root,
Path: path,

IncludeFilesMissingText: c.includeMissing,
}
LogRequest(req)
dir, err := api.FileTreeService.Directory(ctx, req)
Expand Down
4 changes: 4 additions & 0 deletions kythe/go/serving/filetree/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ func (t *Table) Directory(ctx context.Context, req *ftpb.DirectoryRequest) (*ftp
Name: e.Name,
BuildConfig: e.BuildConfig,
Generated: e.GetGenerated(),
MissingText: e.GetMissingText(),
}
switch e.Kind {
case srvpb.FileDirectory_FILE:
re.Kind = ftpb.DirectoryReply_FILE
if !req.GetIncludeFilesMissingText() && e.GetMissingText() {
continue
}
case srvpb.FileDirectory_DIRECTORY:
re.Kind = ftpb.DirectoryReply_DIRECTORY
default:
Expand Down
6 changes: 6 additions & 0 deletions kythe/proto/filetree.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ message DirectoryRequest {
string corpus = 1;
string root = 2;
string path = 3;

// Whether to return files that are missing text.
bool include_files_missing_text = 4;
}

message DirectoryReply {
Expand Down Expand Up @@ -77,6 +80,9 @@ message DirectoryReply {

// True if the entry is generated.
bool generated = 4;

// Whether the FILE entry is missing text.
bool missing_text = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more natural in the positive sense. Though does has_text conflict with proto3 hazzers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The picked the default that would be more common so we don't just populate true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true in every response.

}
enum Kind {
UNKNOWN = 0;
Expand Down
108 changes: 65 additions & 43 deletions kythe/proto/filetree_go_proto/filetree.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.