From 755f391a9f8612d8451ff402eec3099da407cf1f Mon Sep 17 00:00:00 2001 From: David Chalifoux Date: Wed, 24 Jul 2024 09:35:56 -0400 Subject: [PATCH] fix: Fix panic caused by negative file ID --- Cargo.lock | 96 ++++++++++++++++++++++---------------------- src/main.rs | 33 +++++++-------- src/put/files.rs | 20 ++++----- src/put/transfers.rs | 14 +++---- src/put/zips.rs | 6 +-- 5 files changed, 85 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc3dbf0..9047f41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,15 +158,15 @@ dependencies = [ [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "cc" -version = "1.0.106" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "066fce287b1d4eafef758e89e09d724a24808a9196fe9756b8ca90e86d0719a2" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cfg-if" @@ -218,7 +218,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -263,9 +263,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "darling" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ "darling_core", "darling_macro", @@ -273,27 +273,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] name = "darling_macro" -version = "0.20.9" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -517,9 +517,9 @@ dependencies = [ [[package]] name = "http-body" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http", @@ -838,9 +838,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -859,7 +859,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -879,9 +879,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -930,7 +930,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -1175,9 +1175,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", "core-foundation", @@ -1188,9 +1188,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -1213,7 +1213,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -1250,9 +1250,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.8.3" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e73139bc5ec2d45e6c5fd85be5a46949c1c39a4c18e56915f5eb4c12f975e377" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" dependencies = [ "base64", "chrono", @@ -1268,14 +1268,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.8.3" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b80d3d6b56b64335c0180e5ffde23b3c5e08c14c585b51a15bd0e95393f46703" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -1334,9 +1334,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -1408,22 +1408,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", ] [[package]] @@ -1474,9 +1474,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" dependencies = [ "backtrace", "bytes", @@ -1523,9 +1523,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.14" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" +checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" dependencies = [ "serde", "serde_spanned", @@ -1544,9 +1544,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.15" +version = "0.22.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59a3a72298453f564e2b111fa896f8d07fabb36f51f06d7e875fc5e0b5a3ef1" +checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" dependencies = [ "indexmap 2.2.6", "serde", @@ -1714,7 +1714,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -1748,7 +1748,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1919,9 +1919,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +checksum = "374ec40a2d767a3c1b4972d9475ecd557356637be906f2cb3f7fe17a6eb5e22f" dependencies = [ "memchr", ] diff --git a/src/main.rs b/src/main.rs index 10973d1..e6a23d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,7 +66,7 @@ fn cli() -> Command { .arg( Arg::new("FOLDER_ID") .help("Lists the contents of a folder (optional)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(false) .num_args(1) ) @@ -104,7 +104,7 @@ fn cli() -> Command { .arg_required_else_help(true) .arg( Arg::new("FILE_ID") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) .help("ID of a file or folder (required)") ) @@ -116,7 +116,7 @@ fn cli() -> Command { .arg_required_else_help(true) .arg( Arg::new("FILE_ID") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) .help("ID(s) of a file or folder (required)") ) @@ -143,7 +143,7 @@ fn cli() -> Command { .arg_required_else_help(true) .arg( Arg::new("FILE_ID") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) .help("ID(s) of a file (required)") ) @@ -157,7 +157,7 @@ fn cli() -> Command { Arg::new("parent_id") .short('p') .long("parent") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .help("ID of a Put folder to upload to instead of the root folder") .required(false) ) @@ -191,12 +191,12 @@ fn cli() -> Command { .arg( Arg::new("FILE_ID") .help("ID of the file to move (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true)) .arg( Arg::new("PARENT_ID") .help("ID of the new parent folder (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -208,7 +208,7 @@ fn cli() -> Command { .arg( Arg::new("FILE_ID") .help("ID of the file to rename (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) .arg( @@ -230,7 +230,7 @@ fn cli() -> Command { .arg( Arg::new("FILE_ID") .help("ID of the file to extract (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -245,7 +245,7 @@ fn cli() -> Command { .arg( Arg::new("FILE_ID") .help("ID of a video file (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -274,7 +274,7 @@ fn cli() -> Command { Arg::new("parent_id") .short('p') .long("parent") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .help("ID of a Put folder to upload to instead of the root folder") .required(false) ) @@ -287,7 +287,7 @@ fn cli() -> Command { .arg( Arg::new("TRANSFER_ID") .help("ID of a transfer (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -299,7 +299,7 @@ fn cli() -> Command { .arg( Arg::new("TRANSFER_ID") .help("ID of a transfer (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -311,7 +311,7 @@ fn cli() -> Command { .arg( Arg::new("TRANSFER_ID") .help("ID of a transfer (required)") - .value_parser(value_parser!(u32)) + .value_parser(value_parser!(i64)) .required(true) ) ) @@ -443,7 +443,7 @@ fn main() { let folder_id_result = sub_matches.get_one("FOLDER_ID"); - let folder_id: u32 = match folder_id_result { + let folder_id: i64 = match folder_id_result { Some(folder_id) => *folder_id, None => 0, }; @@ -479,7 +479,7 @@ fn main() { Some(("url", sub_matches)) => { require_auth(&client, &config); - let file_id: &u32 = sub_matches + let file_id: &i64 = sub_matches .get_one("FILE_ID") .expect("missing file ID argument"); @@ -564,6 +564,7 @@ fn main() { for path in paths { println!("Uploading: {}\n", path.to_string_lossy()); + ProcessCommand::new("curl") .args(curl_args.clone()) .arg("-H") diff --git a/src/put/files.rs b/src/put/files.rs index cb3321d..8054cca 100644 --- a/src/put/files.rs +++ b/src/put/files.rs @@ -22,13 +22,13 @@ impl fmt::Display for FileSize { #[serde_as] #[derive(Debug, Serialize, Deserialize, Tabled)] pub struct File { - pub id: u32, + pub id: i64, pub name: String, pub file_type: String, pub size: FileSize, pub created_at: String, #[serde_as(as = "DefaultOnNull")] - pub parent_id: u32, + pub parent_id: i64, } #[derive(Debug, Serialize, Deserialize)] @@ -38,7 +38,7 @@ pub struct FilesResponse { } /// Returns the user's files. -pub fn list(client: &Client, api_token: &String, parent_id: u32) -> Result { +pub fn list(client: &Client, api_token: &String, parent_id: i64) -> Result { let response: FilesResponse = client .get(format!( "https://api.put.io/v2/files/list?parent_id={parent_id}" @@ -53,7 +53,7 @@ pub fn list(client: &Client, api_token: &String, parent_id: u32) -> Result, - pub total: u32, + pub total: i64, } /// Searches files for given keyword. @@ -90,7 +90,7 @@ pub struct UrlResponse { } /// Returns a download URL for a given file. -pub fn url(client: &Client, api_token: &String, file_id: u32) -> Result { +pub fn url(client: &Client, api_token: &String, file_id: i64) -> Result { let response: UrlResponse = client .get(format!("https://api.put.io/v2/files/{file_id}/url")) .header("authorization", format!("Bearer {api_token}")) @@ -104,8 +104,8 @@ pub fn url(client: &Client, api_token: &String, file_id: u32) -> Result Result<(), Error> { let form: Form = Form::new() .text("file_ids", file_id.to_string()) @@ -124,7 +124,7 @@ pub fn mv( pub fn rename( client: &Client, api_token: &String, - file_id: u32, + file_id: i64, new_name: &String, ) -> Result<(), Error> { let form = Form::new() @@ -141,7 +141,7 @@ pub fn rename( } /// Extracts ZIP and RAR archives -pub fn extract(client: &Client, api_token: &String, file_id: u32) -> Result<(), Error> { +pub fn extract(client: &Client, api_token: &String, file_id: i64) -> Result<(), Error> { let form: Form = Form::new().text("file_ids", file_id.to_string()); client @@ -181,7 +181,7 @@ pub fn get_extractions(client: &Client, api_token: &String) -> Result, ) -> Result<(), Error> { diff --git a/src/put/transfers.rs b/src/put/transfers.rs index 6ea8f3b..e781c2a 100644 --- a/src/put/transfers.rs +++ b/src/put/transfers.rs @@ -18,9 +18,9 @@ where #[derive(Debug, Serialize, Deserialize, Tabled)] pub struct Transfer { #[serde(default, deserialize_with = "unwrap_or_default")] - pub id: u32, + pub id: i64, #[serde(default, deserialize_with = "unwrap_or_default")] - pub file_id: u32, + pub file_id: i64, #[serde(default, deserialize_with = "unwrap_or_default")] pub name: String, #[serde(default, deserialize_with = "unwrap_or_default")] @@ -50,9 +50,9 @@ pub fn add( client: &Client, api_token: &String, url: &String, - parent_id: Option<&u32>, + parent_id: Option<&i64>, ) -> Result<(), Error> { - let parent_id: u32 = match parent_id { + let parent_id: i64 = match parent_id { Some(id) => *id, None => 0, }; @@ -71,7 +71,7 @@ pub fn add( } /// Cancels or removes transfers -pub fn cancel(client: &Client, api_token: &String, transfer_id: u32) -> Result<(), Error> { +pub fn cancel(client: &Client, api_token: &String, transfer_id: i64) -> Result<(), Error> { let form: Form = Form::new().text("transfer_ids", transfer_id.to_string()); client @@ -94,7 +94,7 @@ pub fn clean(client: &Client, api_token: &String) -> Result<(), Error> { } /// Retries failed transfers -pub fn retry(client: &Client, api_token: &String, transfer_id: u32) -> Result<(), Error> { +pub fn retry(client: &Client, api_token: &String, transfer_id: i64) -> Result<(), Error> { let form: Form = Form::new().text("id", transfer_id.to_string()); client @@ -107,7 +107,7 @@ pub fn retry(client: &Client, api_token: &String, transfer_id: u32) -> Result<() } /// Removes transfers by ID -pub fn remove(client: &Client, api_token: &String, transfer_id: u32) -> Result<(), Error> { +pub fn remove(client: &Client, api_token: &String, transfer_id: i64) -> Result<(), Error> { let form: Form = Form::new().text("transfer_ids", transfer_id.to_string()); client diff --git a/src/put/zips.rs b/src/put/zips.rs index 96f920f..c205b1a 100644 --- a/src/put/zips.rs +++ b/src/put/zips.rs @@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct CreateZipResponse { - pub zip_id: u32, + pub zip_id: i64, } /// Creates a new ZIP job with the given file id. /// /// Waits for the zip job complete, and returns a string with the download URL. -pub fn create(client: &Client, api_token: &String, file_id: u32) -> Result { +pub fn create(client: &Client, api_token: &String, file_id: i64) -> Result { // Start ZIP job let form: Form = Form::new().text("file_ids", file_id.to_string()); @@ -45,7 +45,7 @@ pub struct CheckZipResponse { } /// Checks the status of a given zip job -pub fn get(client: &Client, api_token: &String, zip_id: u32) -> Result { +pub fn get(client: &Client, api_token: &String, zip_id: i64) -> Result { let response: CheckZipResponse = client .get(format!("https://api.put.io/v2/zips/{zip_id}")) .header("authorization", format!("Bearer {api_token}"))