Compare commits
No commits in common. "8cdd0a8fc1d4fa89bcc74e9f121e2d8d81b8489b" and "a941040948e4d6b0ab547f33fd91a64d8e747150" have entirely different histories.
8cdd0a8fc1
...
a941040948
9 changed files with 47 additions and 60 deletions
|
@ -1,7 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="RegExpRepeatedSpace" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"index": true
|
||||
}
|
|
@ -2,11 +2,6 @@
|
|||
Dates are given in YYYY-MM-DD format.
|
||||
|
||||
## v0.3
|
||||
### v0.3.4 (2021-mm-dd)
|
||||
#### Other
|
||||
- Refactored `formats.rs`
|
||||
- More accurate dependency versions in `Cargo.toml` to ensure that the MSRV stays supported
|
||||
|
||||
### v0.3.3 (2021-07-07)
|
||||
#### Features
|
||||
- Added `--canonical-paths` flag for outputting canonical paths in output - for example,
|
||||
|
@ -96,7 +91,7 @@ Dates are given in YYYY-MM-DD format.
|
|||
(files without extensions are still skipped unless the -S flag is used)
|
||||
#### Bugfixes
|
||||
- Fixed compilation on big endian 32-bit architectures (see
|
||||
[here](https://github.com/bodil/smartstring/blob/v0.2.7/src/config.rs#L102-L104) for why that was a problem in the
|
||||
[here](https://github.com/bodil/smartstring/blob/v0.2.6/src/config.rs#L101-L103) for why that was a problem in the
|
||||
first place)
|
||||
- Fixed broken tests for the [`infer`] backend
|
||||
#### Other
|
||||
|
|
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -1,5 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
|
@ -308,9 +310,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.98"
|
||||
version = "0.2.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
|
||||
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
|
@ -344,9 +346,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
|||
|
||||
[[package]]
|
||||
name = "new_mime_guess"
|
||||
version = "2.1.1"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "991337b97f81dff759c3edabb0bc01ceac92bff6f54852853824bbe1acd969f7"
|
||||
checksum = "e714f72c691c7d2b344ec8dd57d7f52b59651f46b9de477fb68363f097d694ae"
|
||||
dependencies = [
|
||||
"mime",
|
||||
"unicase",
|
||||
|
@ -417,9 +419,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.28"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
|
||||
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
@ -569,9 +571,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.66"
|
||||
version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127"
|
||||
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -605,9 +607,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.74"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"
|
||||
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
18
Cargo.toml
18
Cargo.toml
|
@ -27,7 +27,7 @@ json = ["serde", "serde_json"]
|
|||
[dependencies]
|
||||
walkdir = "2.3.2"
|
||||
log = "0.4.14"
|
||||
mime_guess = { package = "new_mime_guess", version = "2.1.1" }
|
||||
mime_guess = { package = "new_mime_guess", version = "2.1.0" }
|
||||
snailquote = "0.3.0"
|
||||
once_cell = "1.8.0"
|
||||
rayon = { version = "1.5.0", optional = true }
|
||||
|
@ -46,17 +46,7 @@ xdg-mime = "0.3.3"
|
|||
infer = { version = "0.5.0", optional = true }
|
||||
|
||||
[target.'cfg(not(all(target_endian = "big", target_pointer_width = "32")))'.dependencies]
|
||||
# the seemingly weird target constraint here is due to this:
|
||||
# https://github.com/bodil/smartstring/blob/v0.2.7/src/config.rs#L102-L104
|
||||
# essentially, smartstring is intentionally blocked from compiling on 32-bit big endian archs, so our dependency on it
|
||||
# needs to be too. otherwise, fif won't work on platforms like powerpc, even though this dependency is the only
|
||||
# blocker -- fif runs just fine on powerpc without smartstring. or at least, just fine under qemu user-mode powerpc ~u0
|
||||
|
||||
# additionally, smartstring 0.2.8 requires rust >=1.46 (due to https://github.com/rust-lang/rust/issues/49146), and
|
||||
# 0.2.3 doesn't impl Display on its SmartString type.
|
||||
# so, we need at least 0.2.4 so we can println! strings, and at most 0.2.7 until we bump the MSRV to at least 1.46.
|
||||
# see https://github.com/bodil/smartstring/blob/master/CHANGELOG.md
|
||||
smartstring = "<= 0.2.7, >= 0.2.4"
|
||||
smartstring = "0.2.6"
|
||||
|
||||
[dependencies.clap]
|
||||
version = "3.0.0-beta.2"
|
||||
|
@ -79,6 +69,10 @@ rand = "0.8.3"
|
|||
[profile.release]
|
||||
lto = "thin"
|
||||
|
||||
# perform some simple optimisations when testing
|
||||
[profile.test]
|
||||
opt-level = 1
|
||||
|
||||
# optimise dependencies, even when producing debug and test builds
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
|
|
@ -122,14 +122,23 @@ fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub trait FormatSteps {
|
||||
// TODO: this might need a restructure.
|
||||
// it would be nice if i didn't have to write a case for every OutputFormat variant that looked like
|
||||
// OutputFormat::PowerShell => PowerShell::new().write_all(...)
|
||||
// also, JSON's implementation differs vastly from PowerShell and Shell's implementations. Maybe they shouldn't be
|
||||
// treated as implementing the same trait, since in that case, the format trait is more of a concept rather than an
|
||||
// actual definition of behaviour.
|
||||
// structuring code is *hard*
|
||||
pub trait Format {
|
||||
fn new() -> Self;
|
||||
fn rename<W: Write>(&self, _f: &mut W, _from: &Path, _to: &Path) -> io::Result<()> { unreachable!() }
|
||||
fn no_known_extension<W: Write>(&self, _f: &mut W, _path: &Path) -> io::Result<()> { unreachable!() }
|
||||
fn unreadable<W: Write>(&self, _f: &mut W, _path: &Path) -> io::Result<()> { unreachable!() }
|
||||
fn unknown_type<W: Write>(&self, _f: &mut W, _path: &Path) -> io::Result<()> { unreachable!() }
|
||||
fn header<W: Write>(&self, _f: &mut W, _entries: &Entries) -> io::Result<()> { unreachable!() }
|
||||
fn footer<W: Write>(&self, _f: &mut W, _entries: &Entries) -> io::Result<()> { unreachable!() }
|
||||
fn write_steps<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> {
|
||||
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> {
|
||||
// TODO: clean this up - it's kinda messy
|
||||
self.header(f, entries)?;
|
||||
|
||||
|
@ -176,18 +185,12 @@ pub trait FormatSteps {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait Format {
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()>;
|
||||
}
|
||||
|
||||
/// Bourne-Shell compatible script.
|
||||
pub struct Shell;
|
||||
pub struct Shell {}
|
||||
|
||||
impl Format for Shell {
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> { self.write_steps(f, entries) }
|
||||
}
|
||||
fn new() -> Self { Self {} }
|
||||
|
||||
impl FormatSteps for Shell {
|
||||
fn rename<W: Write>(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()> {
|
||||
smart_write(f, writablesln!("mv -v -i -- ", from, Space, to))
|
||||
}
|
||||
|
@ -235,13 +238,11 @@ impl FormatSteps for Shell {
|
|||
// PowerShell is a noun, not a type
|
||||
#[allow(clippy::doc_markdown)]
|
||||
/// PowerShell script.
|
||||
pub struct PowerShell;
|
||||
pub struct PowerShell {}
|
||||
|
||||
impl Format for PowerShell {
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> { self.write_steps(f, entries) }
|
||||
}
|
||||
fn new() -> Self { Self {} }
|
||||
|
||||
impl FormatSteps for PowerShell {
|
||||
fn rename<W: Write>(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()> {
|
||||
// unfortunately there doesn't seem to be an equivalent of sh's `mv -i` -- passing the '-Confirm' flag will prompt
|
||||
// the user to confirm every single rename, and using Move-Item -Force will always overwrite without prompting.
|
||||
|
@ -302,10 +303,7 @@ impl FormatSteps for PowerShell {
|
|||
|
||||
pub struct Text;
|
||||
impl Format for Text {
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> { self.write_steps(f, entries) }
|
||||
}
|
||||
|
||||
impl FormatSteps for Text {
|
||||
fn new() -> Self { Self {} }
|
||||
fn rename<W: Write>(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()> {
|
||||
smart_write(f, writablesln![from, " should be renamed to ", to])
|
||||
}
|
||||
|
@ -339,6 +337,8 @@ pub struct Json;
|
|||
|
||||
#[cfg(feature = "json")]
|
||||
impl Format for Json {
|
||||
fn new() -> Self { Self {} }
|
||||
|
||||
fn write_all<W: Write>(&self, f: &mut W, entries: &Entries) -> io::Result<()> {
|
||||
#[derive(serde::Serialize)]
|
||||
struct SerdeEntries<'a> {
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -30,7 +30,7 @@ use walkdir::{DirEntry, WalkDir};
|
|||
|
||||
use crate::findings::Findings;
|
||||
use crate::findings::ScanError;
|
||||
use crate::formats::Format;
|
||||
use crate::formats::{Format, PowerShell, Shell};
|
||||
use crate::mime_db::MimeDb;
|
||||
use crate::parameters::{OutputFormat, ScanOpts};
|
||||
use crate::utils::{clap_long_version, os_name};
|
||||
|
@ -142,17 +142,17 @@ fn main() {
|
|||
|
||||
if results.is_empty() {
|
||||
info!("All files have valid extensions!");
|
||||
exit(exitcode::OK);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
let mut buffered_stdout = BufWriter::new(stdout());
|
||||
|
||||
let result = match args.output_format {
|
||||
OutputFormat::Sh => formats::Shell.write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::PowerShell => formats::PowerShell.write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::Sh => Shell::new().write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::PowerShell => PowerShell::new().write_all(&mut buffered_stdout, &results),
|
||||
#[cfg(feature = "json")]
|
||||
OutputFormat::Json => formats::Json.write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::Text => formats::Text.write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::Json => formats::Json::new().write_all(&mut buffered_stdout, &results),
|
||||
OutputFormat::Text => formats::Text::new().write_all(&mut buffered_stdout, &results),
|
||||
};
|
||||
|
||||
if result.is_err() {
|
||||
|
|
|
@ -352,8 +352,8 @@ fn outputs_move_commands() {
|
|||
let mut contents = std::string::String::new();
|
||||
|
||||
match *format {
|
||||
"Shell" => Shell.write_all(&mut cursor, &entries),
|
||||
"PowerShell" => PowerShell.write_all(&mut cursor, &entries),
|
||||
"Shell" => Shell::new().write_all(&mut cursor, &entries),
|
||||
"PowerShell" => PowerShell::new().write_all(&mut cursor, &entries),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.expect("Failed to write to cursor");
|
||||
|
@ -389,7 +389,7 @@ fn test_json() {
|
|||
let mut cursor = std::io::Cursor::new(Vec::new());
|
||||
let mut contents = std::string::String::new();
|
||||
|
||||
Json
|
||||
Json::new()
|
||||
.write_all(&mut cursor, &entries)
|
||||
.expect("Failed to write to cursor");
|
||||
|
||||
|
|
2
test.py
2
test.py
|
@ -5,7 +5,7 @@ import subprocess
|
|||
import sys
|
||||
|
||||
def test_archs():
|
||||
archs = ["aarch64", "powerpc", "riscv64gc"]
|
||||
archs = ["aarch64", "powerpc"]
|
||||
upto = 1
|
||||
target = len(archs)
|
||||
|
||||
|
|
Loading…
Reference in a new issue