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

Update ListFiles to return directories and add MakeDir endpoint #4552

Merged
merged 6 commits into from
Apr 10, 2024

Conversation

AdityaHegde
Copy link
Collaborator

To prepare for asset explorer,

  1. We need to get empty directories in ListFiles to allow users to add files to them.
  2. We need a way to create a new directory. Adding MakeDir for this.

Note: We do not need this in watch files as of now, since that is used to react to assets.

@AdityaHegde AdityaHegde self-assigned this Apr 9, 2024
Comment on lines 472 to 480
message MakeDirRequest {
string instance_id = 1 [(validate.rules).string = {pattern: "^[_\\-a-zA-Z0-9]+$"}];
string path = 2 [(validate.rules).string.min_len = 1];
// Create indicates whether to create the directory if it doesn't already exist
bool create = 3;
// Will cause the operation to fail if the directory already exists.
// It should only be set when create = true.
bool create_only = 4;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

create and create_only don't really make sense here. Maybe add ignore_if_exists if it's needed?

Comment on lines 81 to 86
rpc MakeDir(MakeDirRequest) returns (MakeDirResponse) {
option (google.api.http) = {
post: "/v1/instances/{instance_id}/files/make-dir/-/{path=**}",
body: "*"
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe CreateDirectory for consistency with other API names?

repeated ListFileEntry files = 1;
}

message ListFileEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this type isn't itself a listing, maybe FileEntry?

Comment on lines 180 to 186
var paths []string
for _, file := range files {
if file.IsDir {
continue
}
paths = append(paths, file.Path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding a skipDirs bool option to ListRecursive instead? It could be useful and would avoid some allocations.

Comment on lines 24 to 27
//withDuckDB,
withFile,
withPostgres,
withSQLite,
//withPostgres,
//withSQLite,
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be reverted

Comment on lines 44 to 47
type FileEntry struct {
Path string
IsDir bool
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we call it DirEntry to align with Go's type name for it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya makes sense

Comment on lines 80 to 81

rpc CreateDirectory(CreateDirectoryRequest) returns (CreateDirectoryResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a docstring :)

@@ -78,6 +78,13 @@ service RuntimeService {
};
}

rpc CreateDirectory(CreateDirectoryRequest) returns (CreateDirectoryResponse) {
option (google.api.http) = {
post: "/v1/instances/{instance_id}/files/make-dir/-/{path=**}",
Copy link
Contributor

Choose a reason for hiding this comment

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

make-dir probably needs to be changed

@@ -448,6 +460,15 @@ message PutFileResponse {
string file_path = 1; // TODO: Redundant, should be removed (but frontend currently uses it)
}

message CreateDirectoryRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring

bool ignore_if_exists = 3;
}

message CreateDirectoryResponse {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring

Comment on lines 180 to 183
var paths []string
for _, file := range files {
paths = append(paths, file.Path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be removed and files renamed to paths (look at the diff vs. main)

Comment on lines 268 to 271
var paths []string
for _, file := range files {
paths = append(paths, file.Path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment

runtime/repos.go Outdated
}
defer release()

// TODO: Handle ignoreIfExists
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we fix this todo (or remove the ignoreIfExists option entirely)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ya i think it makes sense to just remove it. Let it error if the folder exists.

@@ -62,14 +70,14 @@ func (s *Server) WatchFiles(req *runtimev1.WatchFilesRequest, ss runtimev1.Runti
defer release()

if req.Replay {
paths, err := repo.ListRecursive(ss.Context(), "**")
files, err := repo.ListRecursive(ss.Context(), "**", true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't you need to be told about new/deleted directories in WatchFiles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have not updated WatchFiles to include folders just yet. I plan to add it in a follow up.

repeated FileEntry files = 1;
}

message FileEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Add a docstring
  2. If we're calling it DirEntry internally now, we should probably also call it that here to align names

@AdityaHegde AdityaHegde force-pushed the adityahegde/asset-explorer-list-folders branch from 30eda43 to 56d83e8 Compare April 10, 2024 13:24
@begelundmuller begelundmuller merged commit cc1dbba into main Apr 10, 2024
7 checks passed
@begelundmuller begelundmuller deleted the adityahegde/asset-explorer-list-folders branch April 10, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants