Skip to content

Commit

Permalink
Add imdl torrent show
Browse files Browse the repository at this point in the history
The `imdl torrent show` command displays information about on-disk
torrent files. The formatting of the command's output is copied from
torf, an excellent command-line torrent creator, editor, and viewer.

type: added
  • Loading branch information
casey committed Apr 8, 2020
1 parent 6df45e0 commit 99a069a
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 44 deletions.
107 changes: 97 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ default-run = "imdl"
[dependencies]
ansi_term = "0.12"
atty = "0.2"
chrono = "0.4.1"
env_logger = "0.7"
libc = "0.2"
md5 = "0.7"
pretty_assertions = "0.6"
regex = "1"
serde_bencode = "0.2"
serde_bytes = "0.11"
sha1 = "0.6"
snafu = "0.6"
static_assertions = "1"
tempfile = "3"
unicode-width = "0.1"
url = "2"
walkdir = "2.1"

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [References](#references)
- [Alternatives & Prior Art](#alternatives--prior-art)
- [BitTorrent](#bittorrent)
- [Acknowledgments](#acknowledgments)

## General

Expand Down Expand Up @@ -161,3 +162,9 @@ at any time.
| https://wiki.theory.org/index.php/Main_Page | Wiki with lots of information about all aspects of the BitTorrent protocol and implementations. |
| https://archive.org/details/2014_torrent_archive_organized) | Massive 158 GiB archive containing 5.5 million torrents, assembled in 2014. |
| https://github.com/internetarchive/dweb-transport | Github repository hosting The Internet Archive's distributed web and BitTorrent-related software. |

## Acknowledgments

The formatting of `imdl torrent show` is entirely copied from
[torf](https://github.com/rndusr/torf-cli), an excellent command-line torrent
creator, editor, and viewer.
2 changes: 1 addition & 1 deletion bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -euxo pipefail

! grep --color -REn 'FIXME|TODO|XXX' src
! grep --color -REni 'FIXME|TODO|XXX' src
7 changes: 2 additions & 5 deletions src/bencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ impl<'buffer> Value<'buffer> {
Parser::parse(buffer)
}

#[cfg(test)]
fn encode(&self) -> Vec<u8> {
pub(crate) fn encode(&self) -> Vec<u8> {
let mut buffer = Vec::new();
self.encode_into(&mut buffer);
buffer
}

#[cfg(test)]
fn encode_into(&self, buffer: &mut Vec<u8>) {
pub(crate) fn encode_into(&self, buffer: &mut Vec<u8>) {
match self {
Self::Int(value) => {
buffer.push(b'i');
Expand All @@ -49,7 +47,6 @@ impl<'buffer> Value<'buffer> {
}
}

#[cfg(test)]
fn encode_str(buffer: &mut Vec<u8>, contents: &[u8]) {
buffer.extend_from_slice(contents.len().to_string().as_bytes());
buffer.push(b':');
Expand Down
4 changes: 4 additions & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const YI: u128 = ZI << 10;
pub(crate) struct Bytes(pub(crate) u128);

impl Bytes {
pub(crate) fn from(bytes: impl Into<u128>) -> Bytes {
Bytes(bytes.into())
}

pub(crate) fn is_power_of_two(self) -> bool {
self.0 == 0 || self.0 & (self.0 - 1) == 0
}
Expand Down
13 changes: 8 additions & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) use std::{
};

// dependencies
pub(crate) use chrono::{TimeZone, Utc};
pub(crate) use libc::EXIT_FAILURE;
pub(crate) use regex::{Regex, RegexSet};
pub(crate) use serde::{Deserialize, Serialize};
Expand All @@ -29,6 +30,7 @@ pub(crate) use structopt::{
clap::{AppSettings, ArgSettings},
StructOpt,
};
pub(crate) use unicode_width::UnicodeWidthStr;
pub(crate) use url::Url;
pub(crate) use walkdir::WalkDir;

Expand All @@ -45,13 +47,10 @@ pub(crate) use crate::{
pub(crate) use crate::{
bytes::Bytes, env::Env, error::Error, file_info::FileInfo, hasher::Hasher, info::Info,
lint::Lint, metainfo::Metainfo, mode::Mode, opt::Opt, platform::Platform, style::Style,
subcommand::Subcommand, torrent::Torrent, use_color::UseColor,
subcommand::Subcommand, table::Table, torrent::Torrent, torrent_summary::TorrentSummary,
use_color::UseColor,
};

// test modules
#[cfg(test)]
pub(crate) use crate::testing;

// test stdlib types
#[cfg(test)]
pub(crate) use std::{
Expand All @@ -63,6 +62,10 @@ pub(crate) use std::{
time::{Duration, Instant},
};

// test modules
#[cfg(test)]
pub(crate) use crate::testing;

// test structs and enums
#[cfg(test)]
pub(crate) use crate::{capture::Capture, test_env::TestEnv};
17 changes: 7 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ pub(crate) enum Error {
AnnounceEmpty,
#[snafu(display("Failed to parse announce URL: {}", source))]
AnnounceUrlParse { source: url::ParseError },
#[snafu(display("Failed to decode bencode: {}", source))]
BencodeDecode { source: serde_bencode::Error },
#[snafu(display("Failed to deserialize torrent metainfo from `{}`: {}", path.display(), source))]
MetainfoLoad {
source: serde_bencode::Error,
path: PathBuf,
},
#[snafu(display("Failed to serialize torrent metainfo: {}", source))]
MetainfoSerialize { source: serde_bencode::Error },
#[snafu(display("Failed to parse byte count `{}`: {}", text, source))]
ByteParse {
text: String,
Expand Down Expand Up @@ -44,8 +49,6 @@ pub(crate) enum Error {
PieceLengthSmall,
#[snafu(display("Piece length cannot be zero"))]
PieceLengthZero,
#[snafu(display("Serialization failed: {}", source))]
Serialize { source: serde_bencode::Error },
#[snafu(display("Failed to write to standard error: {}", source))]
Stderr { source: io::Error },
#[snafu(display("Failed to write to standard output: {}", source))]
Expand Down Expand Up @@ -77,12 +80,6 @@ impl From<clap::Error> for Error {
}
}

impl From<serde_bencode::Error> for Error {
fn from(source: serde_bencode::Error) -> Self {
Self::Serialize { source }
}
}

impl From<SystemTimeError> for Error {
fn from(source: SystemTimeError) -> Self {
Self::SystemTime { source }
Expand Down
2 changes: 1 addition & 1 deletion src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::common::*;

#[derive(Deserialize, Serialize)]
pub struct Info {
pub private: u8,
pub private: Option<u8>,
#[serde(rename = "piece length")]
pub piece_length: u32,
pub name: String,
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
clippy::implicit_return,
clippy::indexing_slicing,
clippy::integer_arithmetic,
clippy::integer_division,
clippy::large_enum_variant,
clippy::missing_docs_in_private_items,
clippy::needless_pass_by_value,
clippy::option_map_unwrap_or_else,
clippy::option_unwrap_used,
clippy::result_expect_used,
clippy::result_unwrap_used,
clippy::shadow_reuse,
clippy::unreachable,
clippy::wildcard_enum_match_arm
)]
Expand Down Expand Up @@ -62,7 +66,9 @@ mod platform_interface;
mod reckoner;
mod style;
mod subcommand;
mod table;
mod torrent;
mod torrent_summary;
mod use_color;

fn main() {
Expand Down
Loading

0 comments on commit 99a069a

Please sign in to comment.