diff --git a/Cargo.lock b/Cargo.lock index 0874b8e..760dee6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -70,6 +79,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bimap" version = "0.6.3" @@ -149,6 +170,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-targets 0.52.0", ] @@ -178,6 +200,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -218,6 +250,51 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.48", +] + +[[package]] +name = "darling_macro" +version = "0.20.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "digest" version = "0.10.7" @@ -246,7 +323,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -261,6 +338,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + [[package]] name = "enum-ordinalize" version = "3.1.15" @@ -286,6 +369,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding 2.3.1", +] + [[package]] name = "fuser" version = "0.14.0" @@ -399,10 +491,12 @@ dependencies = [ "fuser", "futures", "gdriver-common", + "google-drive3", "serde", "tarpc", "tokio", "tracing", + "yup-oauth2", ] [[package]] @@ -421,6 +515,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -431,6 +526,7 @@ dependencies = [ "confique", "directories", "futures", + "google-drive3", "lazy_static", "libc", "serde", @@ -439,6 +535,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", ] [[package]] @@ -468,6 +565,66 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "google-apis-common" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34c72c9baded4d06742eaaa5def6158f9e28d20a679ad1d5f5deb2bae8358052" +dependencies = [ + "base64 0.13.1", + "chrono", + "http", + "hyper", + "itertools 0.10.5", + "mime", + "serde", + "serde_json", + "serde_with", + "tokio", + "tower-service", + "url 1.7.2", + "yup-oauth2", +] + +[[package]] +name = "google-drive3" +version = "5.0.3+20230115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceed0f4299b62993133e1cebb3747500e7565811ad24c9fe69f70077c5dbbd20" +dependencies = [ + "anyhow", + "google-apis-common", + "http", + "hyper", + "hyper-rustls", + "itertools 0.10.5", + "mime", + "serde", + "serde_json", + "tokio", + "tower-service", + "url 1.7.2", +] + +[[package]] +name = "h2" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -495,12 +652,92 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http", + "hyper", + "log", + "rustls 0.21.10", + "rustls-native-certs", + "tokio", + "tokio-rustls", +] + [[package]] name = "iana-time-zone" version = "0.1.59" @@ -524,6 +761,33 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -532,6 +796,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", + "serde", ] [[package]] @@ -544,6 +809,24 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -599,12 +882,33 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + [[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -622,7 +926,17 @@ checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", ] [[package]] @@ -636,6 +950,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -665,6 +985,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.32.2" @@ -680,6 +1009,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "opentelemetry" version = "0.18.0" @@ -718,7 +1053,7 @@ dependencies = [ "futures-util", "once_cell", "opentelemetry_api", - "percent-encoding", + "percent-encoding 2.3.1", "rand", "thiserror", ] @@ -729,6 +1064,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "page_size" version = "0.6.0" @@ -739,6 +1080,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -828,6 +1175,12 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -902,18 +1255,199 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustls" +version = "0.21.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.2", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-pki-types" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "048a63e5b3ac996d78d402940b5fa47973d2d080c6c6fffa1d0f19c4445310b7" + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.195" @@ -945,6 +1479,34 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +dependencies = [ + "base64 0.13.1", + "chrono", + "hex", + "indexmap 1.9.3", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "serde_yaml" version = "0.9.30" @@ -1000,15 +1562,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "1.0.109" @@ -1094,6 +1674,54 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.35.1" @@ -1101,6 +1729,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", + "bytes", "libc", "mio", "num_cpus", @@ -1108,7 +1737,7 @@ dependencies = [ "socket2", "tokio-macros", "tracing", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1122,6 +1751,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.10", + "tokio", +] + [[package]] name = "tokio-serde" version = "0.8.0" @@ -1162,6 +1801,12 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.40" @@ -1195,6 +1840,17 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-opentelemetry" version = "0.18.0" @@ -1214,11 +1870,24 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.17.0" @@ -1231,12 +1900,27 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.10.1" @@ -1249,6 +1933,34 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +dependencies = [ + "idna 0.1.5", + "matches", + "percent-encoding 1.0.1", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna 0.5.0", + "percent-encoding 2.3.1", +] + [[package]] name = "valuable" version = "0.1.0" @@ -1261,6 +1973,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1361,6 +2082,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -1475,6 +2205,33 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "yup-oauth2" +version = "8.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b61da40aeb0907a65f7fb5c1de83c5a224d6a9ebb83bf918588a2bb744d636b8" +dependencies = [ + "anyhow", + "async-trait", + "base64 0.21.7", + "futures", + "http", + "hyper", + "hyper-rustls", + "itertools 0.12.1", + "log", + "percent-encoding 2.3.1", + "rustls 0.22.2", + "rustls-pemfile", + "seahash", + "serde", + "serde_json", + "time", + "tokio", + "tower-service", + "url 2.5.0", +] + [[package]] name = "zerocopy" version = "0.7.32" @@ -1495,3 +2252,9 @@ dependencies = [ "quote", "syn 2.0.48", ] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/Cargo.toml b/Cargo.toml index 2a59c78..7a69155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,8 @@ tracing="0.1" tokio={ version = "1.35", features = ["rt-multi-thread", "tracing", "fs", "macros"] } serde={ version = "1.0", features = ["serde_derive"] } tarpc = { version = "0.34", features = ["full"] } +tracing-subscriber = { version = "0.3" , features = ["env-filter"]} +google-drive3="5.0" futures="0.3" lazy_static="1.4" chrono="0.4" diff --git a/gdriver-backend/Cargo.toml b/gdriver-backend/Cargo.toml index 8c0ac8b..0e2a1cb 100644 --- a/gdriver-backend/Cargo.toml +++ b/gdriver-backend/Cargo.toml @@ -13,6 +13,9 @@ serde.workspace = true tarpc.workspace = true futures.workspace = true chrono.workspace = true +google-drive3.workspace = true + +yup-oauth2 = "8.3" [dependencies.gdriver-common] -path = "../gdriver-common/" +path = "../gdriver-common" diff --git a/gdriver-backend/src/drive.rs b/gdriver-backend/src/drive.rs index f74cbfd..5df5c0a 100644 --- a/gdriver-backend/src/drive.rs +++ b/gdriver-backend/src/drive.rs @@ -1,17 +1,75 @@ use std::collections::HashMap; +use std::fmt::{Debug, Formatter}; use chrono::{DateTime, Utc}; +use google_drive3::{oauth2, DriveHub}; +use yup_oauth2::hyper::client::HttpConnector; +use yup_oauth2::hyper::Client; +use yup_oauth2::hyper_rustls; +use yup_oauth2::hyper_rustls::HttpsConnector; use crate::prelude::*; +#[derive(Clone)] +pub struct GoogleDrive { + pub hub: DriveHub>, +} +impl Debug for GoogleDrive { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "GoogleDrive") + } +} + +impl GoogleDrive { + pub async fn new() -> Result { + //TODO3: maybe change the path where the auth tokens get stored + let auth = oauth2::read_application_secret("auth/client_secret.json").await?; + + let auth = oauth2::InstalledFlowAuthenticator::builder( + auth, + oauth2::InstalledFlowReturnMethod::HTTPRedirect, + ) + .persist_tokens_to_disk("auth/tokens.json") + .build() + .await?; + let client = Client::builder().build( + hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .https_or_http() + .enable_http1() + .enable_http2() + .build(), + ); + Ok(Self { + hub: DriveHub::new(client, auth), + }) + } +} +#[derive(Debug)] pub struct Drive { tracked_files: HashMap>, + pub hub: GoogleDrive, } impl Drive { - pub fn new() -> Self { - Self { + pub async fn new() -> Result { + let hub = GoogleDrive::new().await?; + Ok(Self { tracked_files: HashMap::new(), - } + hub, + }) + } + pub async fn check_connection(&self) -> bool { + self.hub + .hub + .about() + .get() + .param("fields", "user") + .doit() + .await + .inspect(|x| { + dbg!(x); + }) + .is_ok() } pub fn get_file_tracking_state(&self, id: &DriveId) -> TrackingState { let file = self.tracked_files.get(id); diff --git a/gdriver-backend/src/main.rs b/gdriver-backend/src/main.rs index d20fe81..195c7fe 100644 --- a/gdriver-backend/src/main.rs +++ b/gdriver-backend/src/main.rs @@ -5,9 +5,12 @@ use tarpc::{ server::{self, incoming::Incoming, Channel}, tokio_serde::formats::Json, }; + mod prelude; use crate::prelude::*; pub(crate) use gdriver_common::prelude::*; +use gdriver_common::tracing_subscriber::*; + mod drive; mod sample; mod service; @@ -18,6 +21,8 @@ pub(crate) async fn spawn(fut: impl Future + Send + 'static) { #[tokio::main] async fn main() -> Result<()> { // sample::main().await?; + init_tracing(); + test_tracing(); service::start().await?; Ok(()) } diff --git a/gdriver-backend/src/prelude.rs b/gdriver-backend/src/prelude.rs index fb66c71..3bb482d 100644 --- a/gdriver-backend/src/prelude.rs +++ b/gdriver-backend/src/prelude.rs @@ -1,2 +1,3 @@ pub(crate) use gdriver_common::prelude::result::*; pub(crate) use gdriver_common::prelude::*; +pub(crate) use tracing::*; diff --git a/gdriver-backend/src/service.rs b/gdriver-backend/src/service.rs index bb69780..9193f72 100644 --- a/gdriver-backend/src/service.rs +++ b/gdriver-backend/src/service.rs @@ -8,28 +8,75 @@ use std::ffi::OsString; use std::{path::PathBuf, sync::Arc, thread}; use tarpc::context::Context; use tokio::sync::Mutex; +use tracing::instrument; use crate::drive::Drive; +use crate::prelude::*; use super::*; -#[derive(Clone)] +#[derive(Clone, Debug)] struct GdriverServer { socket_address: SocketAddr, drive: Arc>, } impl GDriverService for GdriverServer { + async fn is_online(self, _: Context) -> bool { + let x = self.drive.lock().await; + x.check_connection().await + } + async fn get_settings(self, _: Context) -> StdResult { Ok(GDriverSettings::default()) //todo actually implement this } async fn get_file_by_name( self, - context: Context, + _context: Context, name: OsString, parent: DriveId, ) -> StdResult { - dbg!(context, name, parent); - Err(GetFileByPathError::Other) + dbg!(&name, &parent); + let name = name.to_str().unwrap_or(""); + info!("Trying to get file by name (lookup): parent: {parent} name: '{name}'"); + let drive = self.drive.lock().await; + let query = format!( + "name = '{name}' and '{}' in parents and trashed=false", + parent.0 + ); + let fields = + "nextPageToken, files(id, name, description, createdTime, mimeType, md5Checksum)"; + let (response, list) = drive + .hub + .hub + .files() + .list() + .q(&query) + .param("fields", fields) + .doit() + .await + .map_err(|e| GetFileByPathError::GoogleDrive(e.into()))?; + //todo check response and response codes, nextpagetoken etc. + dbg!(response); + let file = dbg!(list + .files + .ok_or(GetFileByPathError::NotFound)? + .into_iter() + .next() + .ok_or(GetFileByPathError::NotFound)?); + Ok(DriveId::from( + file.id.ok_or(GetFileByPathError::InvalidData)?, + )) + + // if parent.eq(&ROOT_ID) { + // trace!("root dir"); + // if name == "hi" { + // return Ok(DriveId::from("hi")); + // } + // } + // let drive = self.drive.lock().await; + // // drive. + // + // Err(GetFileByPathError::Other) } async fn get_file_by_path( @@ -48,12 +95,17 @@ impl GDriverService for GdriverServer { todo!() } + #[instrument(skip(context))] async fn get_metadata_for_file( self, context: ::tarpc::context::Context, id: DriveId, ) -> StdResult<(), GetMetadataError> { - todo!() + if id == DriveId::from("hi") { + return Ok(()); + } + info!("trying to get metadata for {id}"); + Err(GetMetadataError::Other) } async fn download_content_for_file( @@ -164,8 +216,8 @@ pub async fn start() -> Result<()> { let config = &CONFIGURATION; println!("Config: {:?}", **config); - let drive = Drive::new(); - let m = Arc::new(Mutex::new(drive)); + let drive = Drive::new().await?; + let drive = Arc::new(Mutex::new(drive)); let server_addr = (config.ip, config.port); let mut listener = tarpc::serde_transport::tcp::listen(&server_addr, Json::default).await?; @@ -184,7 +236,7 @@ pub async fn start() -> Result<()> { let c = channel.transport().peer_addr().unwrap(); let server = GdriverServer { socket_address: c, - drive: m.clone(), + drive: drive.clone(), }; channel.execute(server.serve()).for_each(spawn) }) diff --git a/gdriver-client/Cargo.toml b/gdriver-client/Cargo.toml index dabbee9..bd49126 100644 --- a/gdriver-client/Cargo.toml +++ b/gdriver-client/Cargo.toml @@ -17,6 +17,7 @@ fuser = "0.14.0" bimap = "0.6" futures = "0.3" thiserror = "1.0.56" +tracing-subscriber = "0.3.18" [dependencies.gdriver-common] path = "../gdriver-common" diff --git a/gdriver-client/src/filesystem.rs b/gdriver-client/src/filesystem.rs index a3f60b5..e2973c2 100644 --- a/gdriver-client/src/filesystem.rs +++ b/gdriver-client/src/filesystem.rs @@ -107,12 +107,16 @@ impl fuser::Filesystem for DriveFilesystem { trace!("details: {e:?}"); libc::EBADMSG })?; - + info!( + "Is online: {}", + send_request!(self.gdriver_client.is_online(current_context())).unwrap_or(false) + ); Ok(()) } //endregion //region lookup fn lookup(&mut self, _req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEntry) { + dbg!(&parent, &name); if name.to_str().unwrap().contains('/') { todo!("The name in lookup can contain multiple path segments, not just a single name, directly under the parent") } @@ -123,12 +127,15 @@ impl fuser::Filesystem for DriveFilesystem { } Err(e) => { error!("Got an error during lookup: {e:?}"); + dbg!(&e); match e { FilesystemError::Rpc(_) => reply.error(libc::EREMOTEIO), FilesystemError::IO(_) => reply.error(libc::EIO), - FilesystemError::Service(_) | FilesystemError::NotFound => { - reply.error(libc::ENOENT) + FilesystemError::Service(e) => { + dbg!(e); + reply.error(libc::EBADE); } + FilesystemError::NotFound => reply.error(libc::ENOENT), FilesystemError::Other(e) => { dbg!(e); todo!("Handle other errors and decide what error code should be used here") @@ -140,7 +147,7 @@ impl fuser::Filesystem for DriveFilesystem { //endregion //region open fn open(&mut self, _req: &Request<'_>, ino: u64, flags: i32, reply: ReplyOpen) { - let data = utils::lookup::open(self, ino, HandleFlags::from(flags)); + let data = utils::open(self, ino, HandleFlags::from(flags)); match data { Ok((file_header, flags)) => { reply.opened(file_header, flags.into()); @@ -163,7 +170,10 @@ impl fuser::Filesystem for DriveFilesystem { } mod errors { + use std::backtrace::Backtrace; use std::error::Error; + use std::io; + use std::path::PathBuf; use tarpc::client::RpcError; @@ -176,7 +186,7 @@ mod errors { #[error("Could not find entity specified")] NotFound, #[error("IO Error")] - IO(#[source] Box), + IO(#[from] io::Error), #[error("Service returned Error: {0}")] Service(#[from] GDriverServiceError), #[error("Some other error occurred: {0}")] @@ -247,18 +257,17 @@ mod utils { .get_metadata_for_file(current_context(), id.clone()))? .map_err(GDriverServiceError::from)?; let meta_path = fs.gdriver_settings.get_metadata_file_path(&id); - let metadata = read_inode_attributes_from_meta_file(&meta_path, ino, open_file_handles) - .map_err(FilesystemError::IO)?; + let metadata = + read_inode_attributes_from_meta_file(&meta_path, ino, open_file_handles)?; Ok(metadata) } - - pub(crate) fn open( - fs: &mut DriveFilesystem, - inode: Inode, - flags: HandleFlags, - ) -> StdResult<(FileHandle, HandleFlags), FilesystemError> { - dbg!(&fs, inode, flags); - todo!() - } + } + pub(crate) fn open( + fs: &mut DriveFilesystem, + inode: Inode, + flags: HandleFlags, + ) -> StdResult<(FileHandle, HandleFlags), FilesystemError> { + dbg!(&fs, inode, flags); + todo!() } } diff --git a/gdriver-client/src/filesystem/attributes.rs b/gdriver-client/src/filesystem/attributes.rs index 4bc6ae7..c86d75f 100644 --- a/gdriver-client/src/filesystem/attributes.rs +++ b/gdriver-client/src/filesystem/attributes.rs @@ -137,7 +137,7 @@ pub(crate) fn read_inode_attributes_from_meta_file( meta_path: &Path, inode: Inode, open_file_handles: u64, -) -> Result { +) -> StdResult { let metadata = read_metadata_file(meta_path)?; Ok(read_inode_attributes_from_metadata( metadata, diff --git a/gdriver-client/src/main.rs b/gdriver-client/src/main.rs index b9c6168..70f5420 100644 --- a/gdriver-client/src/main.rs +++ b/gdriver-client/src/main.rs @@ -5,6 +5,7 @@ use std::{error::Error, net::IpAddr, result::Result as StdResult}; use crate::filesystem::DriveFilesystem; use crate::service::create_client; use gdriver_common::ipc::gdriver_service::GDriverServiceClient; +use gdriver_common::tracing_subscriber::{init_tracing, test_tracing}; use gdriver_common::{ipc::sample::*, prelude::*}; use tarpc::{client, tokio_serde::formats::Json}; @@ -12,16 +13,16 @@ type Result = StdResult>; #[tokio::main] async fn main() -> Result<()> { + init_tracing(); + test_tracing(); println!("Hello, world!"); let config = &CONFIGURATION; println!("Config: {:?}", **config); let client: GDriverServiceClient = create_client(config.ip, config.port).await?; let fs = DriveFilesystem::new(client); - mount2( - fs, - Path::new("/tmp/gdriver"), - &[MountOption::RW, MountOption::AutoUnmount], - )?; + let mountpoint = Path::new("/tmp/gdriver"); + std::fs::create_dir_all(mountpoint)?; + mount2(fs, mountpoint, &[MountOption::RW, MountOption::AutoUnmount])?; // service::start().await?; Ok(()) diff --git a/gdriver-common/Cargo.toml b/gdriver-common/Cargo.toml index ff3c2bb..ea4414e 100644 --- a/gdriver-common/Cargo.toml +++ b/gdriver-common/Cargo.toml @@ -13,6 +13,8 @@ libc.workspace = true tokio.workspace = true futures.workspace = true lazy_static.workspace = true +tracing-subscriber.workspace = true +google-drive3.workspace = true confique={ version = "0.2" } thiserror = "1.0" anyhow = "1.0.79" diff --git a/gdriver-common/src/drive_structure/file_handle_flags.rs b/gdriver-common/src/drive_structure/file_handle_flags.rs index 3eb8ca0..05ed733 100644 --- a/gdriver-common/src/drive_structure/file_handle_flags.rs +++ b/gdriver-common/src/drive_structure/file_handle_flags.rs @@ -66,41 +66,41 @@ impl From for HandleFlags { } } -impl Into for HandleFlags { - fn into(self) -> i32 { +impl From for i32 { + fn from(value: HandleFlags) -> Self { let mut flags = 0; - if self.o_append { + if value.o_append { flags |= libc::O_APPEND; } - if self.o_dsync { + if value.o_dsync { flags |= libc::O_DSYNC; } - if self.o_nonblock { + if value.o_nonblock { flags |= libc::O_NONBLOCK; } - if self.o_rsync { + if value.o_rsync { flags |= libc::O_RSYNC; } - if self.o_sync { + if value.o_sync { flags |= libc::O_SYNC; } - if self.o_rdonly { + if value.o_rdonly { flags |= libc::O_RDONLY; } - if self.o_rdwr { + if value.o_rdwr { flags |= libc::O_RDWR; } - if self.o_wronly { + if value.o_wronly { flags |= libc::O_WRONLY; } flags } } -impl Into for HandleFlags { - fn into(self) -> u32 { - let i_num: i32 = self.into(); - i_num as u32 +impl From for u32 { + fn from(value: HandleFlags) -> Self { + let i_num: i32 = value.into(); + i_num as Self } } #[cfg(test)] diff --git a/gdriver-common/src/drive_structure/meta.rs b/gdriver-common/src/drive_structure/meta.rs index 7ffe012..abcd871 100644 --- a/gdriver-common/src/drive_structure/meta.rs +++ b/gdriver-common/src/drive_structure/meta.rs @@ -18,7 +18,7 @@ pub struct Metadata { pub gid: u32, pub xattrs: BTreeMap, Vec>, } -pub fn read_metadata_file(path: &Path) -> Result { +pub fn read_metadata_file(path: &Path) -> StdResult { let reader = File::open(path)?; Ok(serde_json::from_reader(reader)?) } diff --git a/gdriver-common/src/ipc/gdriver_service.rs b/gdriver-common/src/ipc/gdriver_service.rs index 1f4f647..7bae237 100644 --- a/gdriver-common/src/ipc/gdriver_service.rs +++ b/gdriver-common/src/ipc/gdriver_service.rs @@ -8,6 +8,7 @@ use crate::drive_structure::drive_id::DriveId; #[tarpc::service] pub trait GDriverService { + async fn is_online() -> bool; async fn get_settings() -> StdResult; async fn get_file_by_name( name: OsString, @@ -84,6 +85,8 @@ impl Default for GDriverSettings { use errors::*; pub mod errors { use super::*; + use std::error::Error; + use std::fmt::{Display, Formatter}; #[derive(Debug, Serialize, Deserialize, thiserror::Error)] pub enum GDriverServiceError { #[error("Error getting the settings: {0}")] @@ -128,6 +131,33 @@ pub mod errors { pub enum GetFileByPathError { #[error("Other")] Other, + #[error("Google drive error {0:?}")] + GoogleDrive(#[from] GoogleDrive3Error), + // GoogleDrive, + #[error("Could not find any file by that name und the specified parent")] + NotFound, + #[error("The drive returned invalid data")] + InvalidData, + } + #[derive(Debug, Serialize, Deserialize, thiserror::Error)] + pub struct GoogleDrive3Error { + message: String, + dbg_message: String, + } + impl From for GoogleDrive3Error { + fn from(value: google_drive3::Error) -> Self { + let message = value.to_string(); + let dbg_message = format!("{:?}", value); + Self { + message, + dbg_message, + } + } + } + impl Display for GoogleDrive3Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "Google Drive Error") + } } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] @@ -146,22 +176,40 @@ pub mod errors { } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum GetMetadataError {} + pub enum GetMetadataError { + #[error("Other")] + Other, + } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum GetContentError {} + pub enum GetContentError { + #[error("Other")] + Other, + } //#[derive(Debug, Serialize, Deserialize)] //pub enum GetContentError {} #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum GetFileListError {} + pub enum GetFileListError { + #[error("Other")] + Other, + } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum MarkFileAsDeletedError {} + pub enum MarkFileAsDeletedError { + #[error("Other")] + Other, + } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum MarkFileForKeepingLocalError {} + pub enum MarkFileForKeepingLocalError { + #[error("Other")] + Other, + } #[derive(Debug, Serialize, Deserialize, thiserror::Error)] - pub enum UnmarkFileForKeepingLocalError {} + pub enum UnmarkFileForKeepingLocalError { + #[error("Other")] + Other, + } } diff --git a/gdriver-common/src/lib.rs b/gdriver-common/src/lib.rs index d6b340e..ed77d25 100644 --- a/gdriver-common/src/lib.rs +++ b/gdriver-common/src/lib.rs @@ -1,7 +1,10 @@ use serde::{Deserialize, Serialize}; use std::path::Path; +use tracing::{debug, error, info, trace, warn}; + pub mod prelude; pub mod config; pub mod drive_structure; pub mod ipc; +pub mod tracing_subscriber; diff --git a/gdriver-common/src/tracing_subscriber.rs b/gdriver-common/src/tracing_subscriber.rs new file mode 100644 index 0000000..11eba6c --- /dev/null +++ b/gdriver-common/src/tracing_subscriber.rs @@ -0,0 +1,22 @@ +use tracing::*; +use tracing_subscriber::EnvFilter; + +#[inline] +pub fn init_tracing() { + let filter = std::fs::read_to_string("env_filter_tracing").unwrap_or("info".to_string()); + let filter = EnvFilter::new(filter); + tracing_subscriber::fmt() + .compact() + .with_file(true) + .with_line_number(true) + .with_env_filter(filter) + .init() +} + +pub fn test_tracing() { + trace!("Trace"); + debug!("Debug"); + info!("Info"); + warn!("Warn"); + error!("Error"); +}