remove unused crates and code

This commit is contained in:
collin 2022-06-14 16:05:27 -07:00
parent e8bff31356
commit 8f4cdb3705
5 changed files with 37 additions and 447 deletions

269
Cargo.lock generated
View File

@ -42,7 +42,7 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cipher",
"cpufeatures",
"opaque-debug",
@ -140,7 +140,7 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -183,7 +183,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -200,7 +200,7 @@ checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61"
dependencies = [
"addr2line",
"cc",
"cfg-if 1.0.0",
"cfg-if",
"libc",
"miniz_oxide",
"object",
@ -344,12 +344,6 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -443,7 +437,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -458,7 +452,7 @@ dependencies = [
"regex",
"terminal_size",
"unicode-width",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -498,7 +492,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@ -543,7 +537,7 @@ version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
]
@ -553,7 +547,7 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
@ -565,7 +559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
@ -578,7 +572,7 @@ version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"lazy_static",
]
@ -626,7 +620,7 @@ dependencies = [
"openssl-sys",
"schannel",
"socket2",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -641,7 +635,7 @@ dependencies = [
"openssl-sys",
"pkg-config",
"vcpkg",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -689,7 +683,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -716,7 +710,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@ -738,18 +732,6 @@ dependencies = [
"instant",
]
[[package]]
name = "filetime"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"winapi 0.3.9",
]
[[package]]
name = "flate2"
version = "1.0.24"
@ -791,47 +773,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "fsevent"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
dependencies = [
"bitflags",
"fsevent-sys",
]
[[package]]
name = "fsevent-sys"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0"
dependencies = [
"libc",
]
[[package]]
name = "fsio"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1fd087255f739f4f1aeea69f11b72f8080e9c2e7645cd06955dad4a178a49e3"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
dependencies = [
"bitflags",
"fuchsia-zircon-sys",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures-channel"
version = "0.3.21"
@ -914,7 +861,7 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"libc",
"wasi 0.10.2+wasi-snapshot-preview1",
]
@ -1100,42 +1047,13 @@ dependencies = [
"regex",
]
[[package]]
name = "inotify"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f"
dependencies = [
"bitflags",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
dependencies = [
"libc",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
"cfg-if",
]
[[package]]
@ -1183,28 +1101,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "leo-abnf"
version = "1.5.3"
@ -1282,7 +1184,6 @@ dependencies = [
"leo-errors",
"leo-package",
"leo-span",
"notify",
"rand",
"rand_core",
"reqwest",
@ -1309,8 +1210,6 @@ dependencies = [
"serde",
"toml",
"tracing",
"walkdir",
"zip",
]
[[package]]
@ -1407,7 +1306,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
]
[[package]]
@ -1462,25 +1361,6 @@ dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4"
dependencies = [
"cfg-if 0.1.10",
"fuchsia-zircon",
"fuchsia-zircon-sys",
"iovec",
"kernel32-sys",
"libc",
"log",
"miow",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "mio"
version = "0.8.3"
@ -1493,30 +1373,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "mio-extras"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
dependencies = [
"lazycell",
"log",
"mio 0.6.23",
"slab",
]
[[package]]
name = "miow"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d"
dependencies = [
"kernel32-sys",
"net2",
"winapi 0.2.8",
"ws2_32-sys",
]
[[package]]
name = "native-tls"
version = "0.2.10"
@ -1535,17 +1391,6 @@ dependencies = [
"tempfile",
]
[[package]]
name = "net2"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
dependencies = [
"cfg-if 0.1.10",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "nias"
version = "0.5.0"
@ -1562,24 +1407,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "notify"
version = "4.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257"
dependencies = [
"bitflags",
"filetime",
"fsevent",
"fsevent-sys",
"inotify",
"libc",
"mio 0.6.23",
"mio-extras",
"walkdir",
"winapi 0.3.9",
]
[[package]]
name = "num-bigint"
version = "0.4.3"
@ -1669,7 +1496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
@ -1729,7 +1556,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
@ -2040,7 +1867,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -2263,7 +2090,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest",
]
@ -2274,7 +2101,7 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"cpufeatures",
"digest",
]
@ -2430,7 +2257,7 @@ source = "git+https://github.com/AleoHQ/snarkVM.git?rev=85b7a79#85b7a790659168d6
dependencies = [
"aleo-std",
"anyhow",
"cfg-if 1.0.0",
"cfg-if",
"curl",
"hex",
"paste",
@ -2446,7 +2273,7 @@ version = "0.7.5"
source = "git+https://github.com/AleoHQ/snarkVM.git?rev=85b7a79#85b7a790659168d693ebb93bfe49e3b8808fbb41"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
"cfg-if",
"fxhash",
"indexmap",
"itertools",
@ -2508,7 +2335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
dependencies = [
"libc",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -2561,12 +2388,12 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -2585,7 +2412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -2699,12 +2526,12 @@ dependencies = [
"bytes",
"libc",
"memchr",
"mio 0.8.3",
"mio",
"num_cpus",
"once_cell",
"pin-project-lite",
"socket2",
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -2752,7 +2579,7 @@ version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@ -2904,7 +2731,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi 0.3.9",
"winapi",
"winapi-util",
]
@ -2936,7 +2763,7 @@ version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"wasm-bindgen-macro",
]
@ -2961,7 +2788,7 @@ version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2"
dependencies = [
"cfg-if 1.0.0",
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
@ -3006,12 +2833,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi"
version = "0.3.9"
@ -3022,12 +2843,6 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@ -3040,7 +2855,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi 0.3.9",
"winapi",
]
[[package]]
@ -3098,17 +2913,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "ws2_32-sys"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
dependencies = [
"winapi 0.2.8",
"winapi-build",
"winapi",
]
[[package]]

View File

@ -80,9 +80,6 @@ features = ["serde"]
[dependencies.lazy_static]
version = "1.4.0"
[dependencies.notify]
version = "4.0.17"
[dependencies.rand]
version = "0.8"

View File

@ -36,12 +36,6 @@ version = "0.5"
[dependencies.tracing]
version = "0.1"
[dependencies.walkdir]
version = "2"
[dependencies.zip]
version = "0.6"
[dev-dependencies.lazy_static]
version = "1.3.0"

View File

@ -25,6 +25,3 @@ pub use self::manifest::*;
pub mod readme;
pub use self::readme::*;
pub mod zip;
pub use self::zip::*;

View File

@ -1,203 +0,0 @@
// Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! The program package zip file.
use crate::{
imports::IMPORTS_DIRECTORY_NAME,
inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION},
outputs::{
CHECKSUM_FILE_EXTENSION, CIRCUIT_FILE_EXTENSION, OUTPUTS_DIRECTORY_NAME, PROOF_FILE_EXTENSION,
PROVING_KEY_FILE_EXTENSION, VERIFICATION_KEY_FILE_EXTENSION,
},
root::{MANIFEST_FILENAME, README_FILENAME},
source::{SOURCE_DIRECTORY_NAME, SOURCE_FILE_EXTENSION},
};
use leo_errors::{PackageError, Result};
use serde::Deserialize;
use std::{
borrow::Cow,
fs::{
File, {self},
},
io::{Read, Write},
path::Path,
};
use walkdir::WalkDir;
use zip::write::{FileOptions, ZipWriter};
pub static ZIP_FILE_EXTENSION: &str = ".zip";
#[derive(Deserialize)]
pub struct ZipFile {
pub package_name: String,
}
impl ZipFile {
pub fn new(package_name: &str) -> Self {
Self {
package_name: package_name.to_string(),
}
}
pub fn exists_at(&self, path: &Path) -> bool {
let path = self.setup_file_path(path);
path.exists()
}
pub fn get_file_path<'a>(&self, current_dir: &'a Path) -> Cow<'a, Path> {
self.setup_file_path(current_dir)
}
// /// Reads the program bytes from the given file path if it exists.
// pub fn read_from(&self, path: &Path) -> Result<Vec<u8>> {
// let path = self.setup_file_path(path);
//
// Ok(fs::read(&path).map_err(|_| PackageError::FileReadError(path.clone()))?)
// }
/// Writes the current package contents to a zip file.
pub fn write(&self, src_dir: &Path) -> Result<()> {
// Build walkdir iterator from current package
let walkdir = WalkDir::new(src_dir);
// Create zip file
let path = self.setup_file_path(src_dir);
let file = File::create(&path).map_err(PackageError::failed_to_create_zip_file)?;
let mut zip = ZipWriter::new(file);
let options = FileOptions::default()
.compression_method(zip::CompressionMethod::Stored)
.unix_permissions(0o755);
// Walk through files in directory and write desired ones to the zip file
let mut buffer = Vec::new();
for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
let path = entry.path();
let name = path.strip_prefix(src_dir).unwrap();
// Add file/directory exclusion
let included = is_included(name);
tracing::debug!("Checking if {:?} is included - {}", name, included);
if !included {
continue;
}
// Write file or directory
if path.is_file() {
tracing::info!("Adding file {:?} as {:?}", path, name);
#[allow(deprecated)]
zip.start_file_from_path(name, options)
.map_err(PackageError::io_error_zip_file)?;
let mut f = File::open(path).map_err(PackageError::failed_to_open_zip_file)?;
f.read_to_end(&mut buffer)
.map_err(PackageError::failed_to_read_zip_file)?;
zip.write_all(&*buffer)
.map_err(PackageError::failed_to_write_zip_file)?;
buffer.clear();
} else if !name.as_os_str().is_empty() {
// Only if not root Avoids path spec / warning
// and mapname conversion failed error on unzip
tracing::info!("Adding directory {:?} as {:?}", path, name);
#[allow(deprecated)]
zip.add_directory_from_path(name, options)
.map_err(PackageError::io_error_zip_file)?;
}
}
zip.finish().map_err(PackageError::io_error_zip_file)?;
tracing::info!("Package zip file created successfully {:?}", path);
Ok(())
}
/// Removes the zip file at the given path if it exists. Returns `true` on success,
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
pub fn remove(&self, path: &Path) -> Result<bool> {
let path = self.setup_file_path(path);
if !path.exists() {
return Ok(false);
}
fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_zip_file(path))?;
Ok(true)
}
fn setup_file_path<'a>(&self, path: &'a Path) -> Cow<'a, Path> {
let mut path = Cow::from(path);
if path.is_dir() {
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
path.to_mut().push(OUTPUTS_DIRECTORY_NAME);
}
path.to_mut()
.push(format!("{}{}", self.package_name, ZIP_FILE_EXTENSION));
}
path
}
}
/// Check if the file path should be included in the package zip file.
fn is_included(path: &Path) -> bool {
// DO NOT include `imports` and `outputs` directories.
if path.starts_with(IMPORTS_DIRECTORY_NAME) || path.starts_with(OUTPUTS_DIRECTORY_NAME) {
return false;
}
// excluded extensions: `.in`, `.bytes`, `lpk`, `lvk`, `.proof`, `.sum`, `.zip`, `.bytes`
if let Some(true) = path.extension().map(|ext| {
ext.eq(ZIP_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(PROVING_KEY_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(VERIFICATION_KEY_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(PROOF_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(CHECKSUM_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(ZIP_FILE_EXTENSION.trim_start_matches('.'))
| ext.eq(CIRCUIT_FILE_EXTENSION.trim_start_matches('.'))
}) {
return false;
}
// Allow `inputs` folder
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches('/')) {
return true;
}
// Allow `.state` and `.in` files
if let Some(true) = path.extension().map(|ext| {
ext.eq(INPUT_FILE_EXTENSION.trim_start_matches('.')) | ext.eq(STATE_FILE_EXTENSION.trim_start_matches('.'))
}) {
return true;
}
// Allow the README.md and Leo.toml files in the root directory
if (path.ends_with(README_FILENAME) | path.ends_with(MANIFEST_FILENAME)) & (path.parent() == Some(Path::new(""))) {
return true;
}
// Only allow additional files in the `src/` directory
if !path.starts_with(SOURCE_DIRECTORY_NAME.trim_end_matches('/')) {
return false;
}
// Allow the `.leo` files in the `src/` directory
path.extension()
.map(|ext| ext.eq(SOURCE_FILE_EXTENSION.trim_start_matches('.')))
.unwrap_or(false)
}