Andrey Smirnov 6d5ee0ca80
feat(init): unify filesystem walkers for ls/cp APIs (#779)
This unifies low-level filesystem walker code for `ls` and `cp`.

New features:

* `ls` now reports relative filenames
* `ls` now prints symlink destination for symlinks
* `cp` now properly always reports errors from the API
* `cp` now reports all the errors back to the client

Example for `ls`:

```
osctl-linux-amd64 --talosconfig talosconfig ls -l /var
MODE          SIZE(B)   LASTMOD       NAME
drwxr-xr-x    4096      Jun 26 2019   .
Lrwxrwxrwx    4         Jun 25 2019   etc -> /etc
drwxr-xr-x    4096      Jun 26 2019   lib
drwxr-xr-x    4096      Jun 21 2019   libexec
drwxr-xr-x    4096      Jun 26 2019   log
drwxr-xr-x    4096      Jun 21 2019   mail
drwxr-xr-x    4096      Jun 26 2019   opt
Lrwxrwxrwx    6         Jun 21 2019   run -> ../run
drwxr-xr-x    4096      Jun 21 2019   spool
dtrwxrwxrwx   4096      Jun 21 2019   tmp
-rw-------    14979     Jun 26 2019   userdata.yaml
```

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2019-06-26 17:43:09 +03:00

118 lines
3.0 KiB
Protocol Buffer

syntax = "proto3";
package proto;
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
// The Init service definition.
service Init {
rpc CopyOut(CopyOutRequest) returns (stream StreamingData) {}
rpc LS(LSRequest) returns (stream FileInfo) {}
rpc Reboot(google.protobuf.Empty) returns (RebootReply) {}
rpc Shutdown(google.protobuf.Empty) returns (ShutdownReply) {}
rpc Upgrade(UpgradeRequest) returns (UpgradeReply) {}
rpc ServiceList(google.protobuf.Empty) returns (ServiceListReply) {}
}
// The response message containing the reboot status.
message RebootReply {}
// The response message containing the shutdown status.
message ShutdownReply {}
message UpgradeRequest {
string url = 1;
}
message UpgradeReply { string ack = 1; }
message ServiceListReply {
repeated ServiceInfo services = 1;
}
message ServiceInfo {
string id = 1;
string state = 2;
ServiceEvents events = 3;
ServiceHealth health = 4;
}
message ServiceEvents {
repeated ServiceEvent events = 1;
}
message ServiceEvent {
string msg = 1;
string state = 2;
google.protobuf.Timestamp ts = 3;
}
message ServiceHealth {
bool unknown = 1;
bool healthy = 2;
string lastMessage = 3;
google.protobuf.Timestamp lastChange = 4;
}
message StopRequest { string id = 1; }
message StopReply { string resp = 1; }
// StreamingData is used to stream back responses
message StreamingData {
bytes bytes = 1;
string errors = 2;
}
// CopyOutRequest describes a request to copy data out of Talos node
//
// CopyOut produces .tar.gz archive which is streamed back to the caller
message CopyOutRequest {
// Root path to start copying data out, it might be either a file or directory
string root_path = 1;
}
// LSRequest describes a request to list the contents of a directory
message LSRequest {
// Root indicates the root directory for the list. If not indicated, '/' is presumed.
string root = 1;
// Recurse indicates that subdirectories should be recursed.
bool recurse = 2;
// RecursionDepth indicates how many levels of subdirectories should be recursed. The default (0) indicates that no limit should be enforced.
int32 recursion_depth = 3;
}
// FileInfo describes a file or directory's information
message FileInfo {
// Name is the name (including prefixed path) of the file or directory
string name = 1;
// Size indicates the number of bytes contained within the file
int64 size = 2;
// Mode is the bitmap of UNIX mode/permission flags of the file
uint32 mode = 3;
// Modified indicates the UNIX timestamp at which the file was last modified
int64 modified = 4; // TODO: unix timestamp or include proto's Date type
// IsDir indicates that the file is a directory
bool is_dir = 5;
// Error describes any error encountered while trying to read the file information.
string error = 6;
// Link is filled with symlink target
string link = 7;
// RelativeName is the name of the file or directory relative to the RootPath
string relative_name = 8;
}