Skip to content

Commit

Permalink
Merge pull request #22 from acridotheres/20-add-clippy-to-ci
Browse files Browse the repository at this point in the history
Add Clippy to CI (v0.2.1)
  • Loading branch information
Le0X8 authored Aug 2, 2024
2 parents 92b0704 + d3667c4 commit b152597
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 96 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run CI
on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
jobs:
ci:
runs-on: ubuntu-latest

steps:
- name: Set up Rust
uses: actions/checkout@v4
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run clippy
run: cargo clippy --verbose -- -D warnings
- name: Run audit
run: cargo audit
18 changes: 0 additions & 18 deletions .github/workflows/tests.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"tamasfe.even-better-toml",
"github.remotehub",
"dustypomerleau.rust-syntax",
"rust-lang.rust-analyzer"
"rust-lang.rust-analyzer",
"vadimcn.vscode-lldb",
"usernamehw.errorlens",
"gruntfuggly.todo-tree"
]
}
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"editor.tabSize": 4
"editor.tabSize": 4,
"errorLens.enabled": true,
"errorLens.gutterIconsEnabled": true,
"errorLens.gutterIconSet": "squareRounded",
"todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^[ \\t]*(-|\\d+.))\\s*($TAGS)|todo!|unimplemented!",
"rust-analyzer.check.command": "clippy",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
},
}
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = 'acridotheres_core'
version = '0.1.1'
version = '0.2.1'
edition = '2021'

[lib]
name = 'corelib'
path = 'src/lib.rs'

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
76 changes: 37 additions & 39 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ pub fn metadata<'a>(
let metadata = match format {
Formats::Zip => {
let metadata = formats::zip::parser::metadata(&mut file);
if check_integrity {
if !formats::zip::parser::check_integrity_all(
if check_integrity
&& !formats::zip::parser::check_integrity_all(
&mut file,
&metadata.files,
&buffer_size,
) {
return Err("Integrity check failed".to_string());
}
)
{
return Err("Integrity check failed".to_string());
}
OriginalArchiveMetadata::Zip(metadata)
}
Expand All @@ -61,14 +61,14 @@ pub fn extract(
let metadata: &dyn ArchiveMetadata = match format {
Formats::Zip => {
let metadata = formats::zip::parser::metadata(&mut file);
if check_integrity {
if !formats::zip::parser::check_integrity_all(
if check_integrity
&& !formats::zip::parser::check_integrity_all(
&mut file,
&metadata.files,
&buffer_size,
) {
return Err("Integrity check failed".to_string());
}
)
{
return Err("Integrity check failed".to_string());
}
&metadata.clone() as &dyn ArchiveMetadata
}
Expand All @@ -85,35 +85,33 @@ pub fn extract(
});
}
}
} else {
if index != None {
let index = index.unwrap();
if index >= files.len() as u32 {
return Err("Index out of range".to_string());
}
formats::zip::parser::extract(
&mut file,
&formats::zip::to_zip_entries(files),
&buffer_size,
&|path| format!("{}/{}", &output, &path),
);
} else {
let path = path.unwrap();
let files: Vec<ZipFileEntry> = metadata
.get_files()
.iter()
.filter_map(|file| {
if file.get_path().starts_with(&path) {
Some(formats::zip::to_zip_entry(*file))
} else {
None
}
})
.collect();
formats::zip::parser::extract(&mut file, &files, &buffer_size, &|path| {
format!("{}/{}", &output, &path)
});
} else if index.is_some() {
let index = index.unwrap();
if index >= files.len() as u32 {
return Err("Index out of range".to_string());
}
formats::zip::parser::extract(
&mut file,
&formats::zip::to_zip_entries(files),
&buffer_size,
&|path| format!("{}/{}", &output, &path),
);
} else {
let path = path.unwrap();
let files: Vec<ZipFileEntry> = metadata
.get_files()
.iter()
.filter_map(|file| {
if file.get_path().starts_with(&path) {
Some(formats::zip::to_zip_entry(*file))
} else {
None
}
})
.collect();
formats::zip::parser::extract(&mut file, &files, &buffer_size, &|path| {
format!("{}/{}", &output, &path)
});
};

Ok(())
Expand All @@ -127,7 +125,7 @@ pub struct EntrySource<'a> {
pub fn create(
format: Formats,
output: String,
input: &mut Vec<EntrySource>,
input: &mut [EntrySource],
buffer_size: u64,
) -> Result<(), String> {
let mut file = FileWriter::new(&output, &false);
Expand Down
6 changes: 3 additions & 3 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> FileReader {
let mut remaining = *len;

while remaining > 0 {
let to_read = min(*buffer_size as u64, remaining) as usize;
let to_read = min(*buffer_size, remaining) as usize;
let read = self.read(&mut buf[..to_read]);
target.write(read);
remaining -= to_read as u64;
Expand All @@ -122,7 +122,7 @@ impl<'a> FileReader {
Times {
created: metadata
.created()
.unwrap_or_else(|_| metadata.modified().unwrap().into())
.unwrap_or_else(|_| metadata.modified().unwrap())
.into(),
accessed: metadata.accessed().unwrap().into(),
modified: metadata.modified().unwrap().into(),
Expand Down Expand Up @@ -238,7 +238,6 @@ impl<'a> FileWriter {
pub fn new(path: &'a String, append: &bool) -> Self {
if *append {
let mut file = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open(path)
Expand All @@ -254,6 +253,7 @@ impl<'a> FileWriter {
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(path)
.unwrap();
file.rewind().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub enum Formats {
Zip,
}

pub fn from_string(format: &String) -> Formats {
match format.as_str() {
pub fn from_string(format: &str) -> Formats {
match format {
"zip" => Formats::Zip,
_ => panic!("Unsupported format"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/formats/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a> FileEntry<'a> for ZipFileEntry<'a> {
}

fn get_original(&'a self) -> OriginalFileEntry<'a> {
OriginalFileEntry::Zip(&self)
OriginalFileEntry::Zip(self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/formats/zip/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn extract(
&entry.offset,
&entry.size,
&mut target,
&entry.modified.into(),
&entry.modified,
buffer_size,
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/formats/zip/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn write(target: &mut FileWriter, data: &mut ZipArchiveData, buffer_size: &u
&file.offset,
&file.size,
target,
&file.modified.into(),
&file.modified,
buffer_size,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/hash/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub fn hash(file: &mut FileReader, offset: &u64, size: &u64, buffer_size: &u64)

let mut remaining = *size;
while remaining > 0 {
let to_read = min(*buffer_size as u64, remaining) as usize;
let to_read = min(*buffer_size, remaining) as usize;
let read = file.read(&mut buf[..to_read]);
hasher.update(&read);
hasher.update(read);
remaining -= to_read as u64;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

pub mod archive;
pub mod file;
pub mod formats;
Expand Down
2 changes: 0 additions & 2 deletions tests/other.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use corelib;

#[test]
fn returns_real_version() {
assert_eq!(corelib::get_version(), env!("CARGO_PKG_VERSION"));
Expand Down
32 changes: 10 additions & 22 deletions tests/zip-external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ use corelib::{

#[test]
fn sample_000_metadata() {
let metadata = match *archive::metadata(
let OriginalArchiveMetadata::Zip(metadata) = *archive::metadata(
Formats::Zip,
"tests/samples/zip/000.zip".to_string(),
true,
1024,
)
.unwrap()
{
OriginalArchiveMetadata::Zip(metadata) => metadata,
};
.unwrap();
assert_eq!(metadata.files.len(), 1);
assert_eq!(metadata.files[0].path, "test.txt");
assert_eq!(metadata.files[0].size, 14);
Expand Down Expand Up @@ -49,16 +46,13 @@ fn sample_000_extract() {

#[test]
fn sample_001_metadata() {
let metadata = match *archive::metadata(
let OriginalArchiveMetadata::Zip(metadata) = *archive::metadata(
Formats::Zip,
"tests/samples/zip/001.zip".to_string(),
true,
1024,
)
.unwrap()
{
OriginalArchiveMetadata::Zip(metadata) => metadata,
};
.unwrap();
assert_eq!(metadata.files.len(), 2);
assert_eq!(metadata.files[0].path, "test.txt");
assert_eq!(metadata.files[0].size, 14);
Expand Down Expand Up @@ -103,16 +97,13 @@ fn sample_001_extract() {

#[test]
fn sample_002_metadata() {
let metadata = match *archive::metadata(
let OriginalArchiveMetadata::Zip(metadata) = *archive::metadata(
Formats::Zip,
"tests/samples/zip/002.zip".to_string(),
true,
1024,
)
.unwrap()
{
OriginalArchiveMetadata::Zip(metadata) => metadata,
};
.unwrap();
assert_eq!(metadata.files.len(), 3);
assert_eq!(metadata.files[0].path, "test/");
assert_eq!(metadata.files[0].size, 0);
Expand Down Expand Up @@ -176,7 +167,7 @@ fn create_000_metadata() {
archive::create(
Formats::Zip,
"tests/samples/zip/c000-external.zip".to_string(),
&mut vec![EntrySource {
&mut [EntrySource {
path: "test.txt".to_string(),
source: &mut FsFile::new(&"tests/samples/zip/c000-external/test.txt".to_string()),
}],
Expand All @@ -186,16 +177,13 @@ fn create_000_metadata() {

std::fs::remove_dir_all("tests/samples/zip/c000-external").unwrap();

let metadata = match *archive::metadata(
let OriginalArchiveMetadata::Zip(metadata) = *archive::metadata(
Formats::Zip,
"tests/samples/zip/c000-external.zip".to_string(),
true,
1024,
)
.unwrap()
{
OriginalArchiveMetadata::Zip(metadata) => metadata,
};
.unwrap();

assert_eq!(metadata.files.len(), 1);
assert_eq!(metadata.files[0].path, "test.txt");
Expand Down Expand Up @@ -227,7 +215,7 @@ fn create_000_extract() {
archive::create(
Formats::Zip,
"tests/samples/zip/c000-external2.zip".to_string(),
&mut vec![EntrySource {
&mut [EntrySource {
path: "test.txt".to_string(),
source: &mut FsFile::new(&"tests/samples/zip/c000-external2/test.txt".to_string()),
}],
Expand Down

0 comments on commit b152597

Please sign in to comment.