From 3d267b09062d5e3c27ab78b7cfaeae923d67bf95 Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Fri, 30 Apr 2021 02:57:54 -0500 Subject: [PATCH] update to marine 0.6.2, remove unsafe --- url-downloader/curl_adapter/Cargo.lock | 105 +++++++++++++++++++--- url-downloader/curl_adapter/Cargo.toml | 2 +- url-downloader/curl_adapter/src/main.rs | 26 +++--- url-downloader/facade/Cargo.lock | 109 ++++++++++++++++++++--- url-downloader/facade/Cargo.toml | 4 +- url-downloader/facade/src/main.rs | 30 +++---- url-downloader/local_storage/Cargo.lock | 105 +++++++++++++++++++--- url-downloader/local_storage/Cargo.toml | 2 +- url-downloader/local_storage/src/main.rs | 27 +++--- 9 files changed, 325 insertions(+), 85 deletions(-) diff --git a/url-downloader/curl_adapter/Cargo.lock b/url-downloader/curl_adapter/Cargo.lock index 4990c32..4dae181 100644 --- a/url-downloader/curl_adapter/Cargo.lock +++ b/url-downloader/curl_adapter/Cargo.lock @@ -1,11 +1,30 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "curl_adapter" version = "0.1.0" @@ -15,29 +34,41 @@ dependencies = [ ] [[package]] -name = "fluence" -version = "0.5.0" +name = "fce-timestamp-macro" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342831732a977f13220ecd6f25c7e6b6127af8d3794d42e3c880b05e457a0484" +checksum = "3c59a6302902583b2c84e87de9d72b949da4396a369baf0aaa49e97021600bb0" dependencies = [ + "chrono", + "quote", +] + +[[package]] +name = "fluence" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b731bd4a69a3945186f2ff96ff753908939c8a2debd60e1f0e8edb6a28757f8" +dependencies = [ + "fce-timestamp-macro", "fluence-sdk-macro", "fluence-sdk-main", + "serde", ] [[package]] name = "fluence-sdk-macro" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c840552e5e58b62d4a272e3e4aabd548e1a4519df629a51d42157c7ecbe653" +checksum = "cb43d2f51f1becb70e2125ef8ca9759597900f95cc22ce7dca981a7d6ccd7dde" dependencies = [ "fluence-sdk-wit", ] [[package]] name = "fluence-sdk-main" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f1d126f05a798c8f812fbe47a42145478ce8029e00411b04d1c5194ab368313" +checksum = "a78910d85e3cdcb9c2baf56144f20a99925c67ac445d4156220c005bfd2f9604" dependencies = [ "fluence-sdk-macro", "log", @@ -46,9 +77,9 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ac71e8d48a8e2bdaccf59572dc7a8e8a1ad0de512fc452107756e37ac0bf752" +checksum = "eab3ed39703b72e0e52bce9e1760746c73f65a5694c8da4dec751d3bfdec15b8" dependencies = [ "proc-macro2", "quote", @@ -90,6 +121,25 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "proc-macro2" version = "1.0.24" @@ -156,6 +206,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "unicode-xid" version = "0.2.1" @@ -173,6 +234,28 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/url-downloader/curl_adapter/Cargo.toml b/url-downloader/curl_adapter/Cargo.toml index 5080e66..c171ec2 100644 --- a/url-downloader/curl_adapter/Cargo.toml +++ b/url-downloader/curl_adapter/Cargo.toml @@ -10,5 +10,5 @@ path = "src/main.rs" name = "curl_adapter" [dependencies] -fluence = { version = "=0.5.0", features = ["logger"] } +fluence = { version = "=0.6.2", features = ["logger"] } log = "0.4.8" diff --git a/url-downloader/curl_adapter/src/main.rs b/url-downloader/curl_adapter/src/main.rs index 5903153..d0ac982 100644 --- a/url-downloader/curl_adapter/src/main.rs +++ b/url-downloader/curl_adapter/src/main.rs @@ -1,5 +1,5 @@ /* - * Copyright 2020 Fluence Labs Limited + * Copyright 2021 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,12 @@ #![allow(improper_ctypes)] use fluence::fce; +use fluence::module_manifest; +use fluence::MountedBinaryResult; use fluence::WasmLoggerBuilder; -use fluence::MountedBinaryResult as Result; -use fluence::MountedBinaryStringResult as StringResult; + +module_manifest!(); /// Log level can be changed by `RUST_LOG` env as well. pub fn main() { @@ -28,21 +30,17 @@ pub fn main() { } #[fce] -pub fn request(url: String) -> StringResult { - unsafe { curl(vec![url]) }.stringify().unwrap() +pub fn download(url: String) -> String { + log::info!("download called with url {}\n", url); + + let result = curl(vec![url]); + + String::from_utf8(result.stdout).unwrap() } -#[fce] -pub fn download(url: String) -> Result { - log::info!("download called with url {}", url); - - unsafe { curl(vec![url]) } -} - - /// Permissions in `Config.toml` should exist to use host functions. #[fce] #[link(wasm_import_module = "host")] extern "C" { - fn curl(cmd: Vec) -> Result; + fn curl(cmd: Vec) -> MountedBinaryResult; } diff --git a/url-downloader/facade/Cargo.lock b/url-downloader/facade/Cargo.lock index d98a1f5..fc200b2 100644 --- a/url-downloader/facade/Cargo.lock +++ b/url-downloader/facade/Cargo.lock @@ -2,9 +2,15 @@ # It is not intended for manual editing. [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "base64" @@ -18,6 +24,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "facade" version = "0.1.0" @@ -29,29 +48,41 @@ dependencies = [ ] [[package]] -name = "fluence" -version = "0.5.0" +name = "fce-timestamp-macro" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342831732a977f13220ecd6f25c7e6b6127af8d3794d42e3c880b05e457a0484" +checksum = "3c59a6302902583b2c84e87de9d72b949da4396a369baf0aaa49e97021600bb0" dependencies = [ + "chrono", + "quote", +] + +[[package]] +name = "fluence" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b731bd4a69a3945186f2ff96ff753908939c8a2debd60e1f0e8edb6a28757f8" +dependencies = [ + "fce-timestamp-macro", "fluence-sdk-macro", "fluence-sdk-main", + "serde", ] [[package]] name = "fluence-sdk-macro" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c840552e5e58b62d4a272e3e4aabd548e1a4519df629a51d42157c7ecbe653" +checksum = "cb43d2f51f1becb70e2125ef8ca9759597900f95cc22ce7dca981a7d6ccd7dde" dependencies = [ "fluence-sdk-wit", ] [[package]] name = "fluence-sdk-main" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f1d126f05a798c8f812fbe47a42145478ce8029e00411b04d1c5194ab368313" +checksum = "a78910d85e3cdcb9c2baf56144f20a99925c67ac445d4156220c005bfd2f9604" dependencies = [ "fluence-sdk-macro", "log", @@ -60,9 +91,9 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ac71e8d48a8e2bdaccf59572dc7a8e8a1ad0de512fc452107756e37ac0bf752" +checksum = "eab3ed39703b72e0e52bce9e1760746c73f65a5694c8da4dec751d3bfdec15b8" dependencies = [ "proc-macro2", "quote", @@ -104,6 +135,25 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "proc-macro2" version = "1.0.24" @@ -170,6 +220,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "unicode-xid" version = "0.2.1" @@ -187,6 +248,28 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/url-downloader/facade/Cargo.toml b/url-downloader/facade/Cargo.toml index 7c71f24..22763ab 100644 --- a/url-downloader/facade/Cargo.toml +++ b/url-downloader/facade/Cargo.toml @@ -10,7 +10,7 @@ name = "facade" path = "src/main.rs" [dependencies] -fluence = { version = "=0.5.0", features = ["logger"]} -anyhow = "1.0.31" +fluence = { version = "=0.6.2", features = ["logger"]} +anyhow = "1.0.40" log = "0.4.8" base64 = "0.13.0" diff --git a/url-downloader/facade/src/main.rs b/url-downloader/facade/src/main.rs index 4f2eb8c..8bda74e 100644 --- a/url-downloader/facade/src/main.rs +++ b/url-downloader/facade/src/main.rs @@ -1,5 +1,5 @@ /* - * Copyright 2020 Fluence Labs Limited + * Copyright 2021 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ use fluence::fce; use fluence::module_manifest; use fluence::WasmLoggerBuilder; -use fluence::MountedBinaryResult as Result; module_manifest!(); @@ -30,31 +29,22 @@ pub fn main() { /// Calls `curl` and stores returned result into a file. #[fce] pub fn get_n_save(url: String, file_name: String) -> String { - let result = unsafe { download(url) }; - if result.is_success() { - log::info!("saving file {}", file_name); - unsafe { file_put(file_name, result.stdout) } - } else { - log::error!("download failed: {:#?}", result.as_std()); - format!("download failed: {:#?}", result.as_std()) - } + log::info!("get_n_save called with {} {}\n", url, file_name); + + let result = download(url); + file_put(file_name, result.into_bytes()); + + String::from("Ok") } -#[fce] -/// Loads file from disk and returns its content as base64 -pub fn load_file(file_name: String) -> String { - let bytes = unsafe { file_get(file_name) }; - base64::encode(bytes) -} - -/// Import `curl_adapter` module +/// Importing `curl` module #[fce] #[link(wasm_import_module = "curl_adapter")] extern "C" { - pub fn download(url: String) -> Result; + pub fn download(url: String) -> String; } -/// Import `local_storage` module +/// Importing `local_storage` module #[fce] #[link(wasm_import_module = "local_storage")] extern "C" { diff --git a/url-downloader/local_storage/Cargo.lock b/url-downloader/local_storage/Cargo.lock index 179a920..5ccd9d3 100644 --- a/url-downloader/local_storage/Cargo.lock +++ b/url-downloader/local_storage/Cargo.lock @@ -1,5 +1,11 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "cfg-if" version = "1.0.0" @@ -7,29 +13,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "fluence" -version = "0.5.0" +name = "chrono" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342831732a977f13220ecd6f25c7e6b6127af8d3794d42e3c880b05e457a0484" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "fce-timestamp-macro" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c59a6302902583b2c84e87de9d72b949da4396a369baf0aaa49e97021600bb0" +dependencies = [ + "chrono", + "quote", +] + +[[package]] +name = "fluence" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b731bd4a69a3945186f2ff96ff753908939c8a2debd60e1f0e8edb6a28757f8" +dependencies = [ + "fce-timestamp-macro", "fluence-sdk-macro", "fluence-sdk-main", + "serde", ] [[package]] name = "fluence-sdk-macro" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c840552e5e58b62d4a272e3e4aabd548e1a4519df629a51d42157c7ecbe653" +checksum = "cb43d2f51f1becb70e2125ef8ca9759597900f95cc22ce7dca981a7d6ccd7dde" dependencies = [ "fluence-sdk-wit", ] [[package]] name = "fluence-sdk-main" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f1d126f05a798c8f812fbe47a42145478ce8029e00411b04d1c5194ab368313" +checksum = "a78910d85e3cdcb9c2baf56144f20a99925c67ac445d4156220c005bfd2f9604" dependencies = [ "fluence-sdk-macro", "log", @@ -38,9 +69,9 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ac71e8d48a8e2bdaccf59572dc7a8e8a1ad0de512fc452107756e37ac0bf752" +checksum = "eab3ed39703b72e0e52bce9e1760746c73f65a5694c8da4dec751d3bfdec15b8" dependencies = [ "proc-macro2", "quote", @@ -90,6 +121,25 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "proc-macro2" version = "1.0.24" @@ -156,6 +206,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "unicode-xid" version = "0.2.1" @@ -173,6 +234,28 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/url-downloader/local_storage/Cargo.toml b/url-downloader/local_storage/Cargo.toml index c89e8b4..5f8879c 100644 --- a/url-downloader/local_storage/Cargo.toml +++ b/url-downloader/local_storage/Cargo.toml @@ -10,5 +10,5 @@ name = "local_storage" path = "src/main.rs" [dependencies] -fluence = { version = "=0.5.0", features = ["logger"]} +fluence = { version = "=0.6.2", features = ["logger"]} log = "0.4.8" diff --git a/url-downloader/local_storage/src/main.rs b/url-downloader/local_storage/src/main.rs index 0f50966..1ec96ea 100644 --- a/url-downloader/local_storage/src/main.rs +++ b/url-downloader/local_storage/src/main.rs @@ -1,5 +1,5 @@ /* - * Copyright 2020 Fluence Labs Limited + * Copyright 2021 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,14 @@ * limitations under the License. */ -use std::fs; use fluence::fce; +use fluence::module_manifest; use fluence::WasmLoggerBuilder; -use std::path::Path; + +use std::fs; +use std::path::PathBuf; + +module_manifest!(); const SITES_DIR: &str = "/sites/"; @@ -28,14 +32,13 @@ pub fn main() { /// You can read or write files from the file system if there is permission to use directories described in `Config.toml`. #[fce] -pub fn put(file_name: String, file_content: Vec) -> String { - log::info!("put called with file name {}", file_name); +pub fn put(name: String, file_content: Vec) -> String { + log::info!("put called with file name {}\n", name); + let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name); - let path = Path::new(SITES_DIR).join(file_name); - - let result = fs::write(&path, file_content); + let result = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content); if let Err(e) = result { - return format!("file {} can't be written: {}", path.to_string_lossy(), e); + return format!("file can't be written: {}", e); } String::from("Ok") @@ -43,9 +46,9 @@ pub fn put(file_name: String, file_content: Vec) -> String { #[fce] pub fn get(file_name: String) -> Vec { - log::info!("get called with file name: {}", file_name); + log::info!("get called with file name: {}\n", file_name); - let path = Path::new(SITES_DIR).join(file_name); + let tmp_filepath = format!("{}{}", SITES_DIR, file_name); - fs::read(&path).unwrap_or_else(|err| format!("error while reading file {}: {}", path.to_string_lossy(), err).into_bytes()) + fs::read(tmp_filepath).unwrap_or_else(|_| b"error while reading file".to_vec()) }