mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 14:37:45 +00:00
refactor/shred ~ polish spelling (comments, names, and exceptions)
This commit is contained in:
parent
13561cb5ae
commit
a15f8af99f
1 changed files with 16 additions and 16 deletions
|
@ -6,7 +6,7 @@
|
||||||
// * For the full copyright and license information, please view the LICENSE
|
// * For the full copyright and license information, please view the LICENSE
|
||||||
// * file that was distributed with this source code.
|
// * file that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) NAMESET FILESIZE fstab coeff journaling writeback REiser journaled
|
// spell-checker:ignore (words) writeback wipesync
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use rand::{Rng, ThreadRng};
|
use rand::{Rng, ThreadRng};
|
||||||
|
@ -25,7 +25,7 @@ extern crate uucore;
|
||||||
static NAME: &str = "shred";
|
static NAME: &str = "shred";
|
||||||
static VERSION_STR: &str = "1.0.0";
|
static VERSION_STR: &str = "1.0.0";
|
||||||
const BLOCK_SIZE: usize = 512;
|
const BLOCK_SIZE: usize = 512;
|
||||||
const NAMESET: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
|
const NAME_CHARSET: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
|
||||||
|
|
||||||
// Patterns as shown in the GNU coreutils shred implementation
|
// Patterns as shown in the GNU coreutils shred implementation
|
||||||
const PATTERNS: [&[u8]; 22] = [
|
const PATTERNS: [&[u8]; 22] = [
|
||||||
|
@ -59,10 +59,10 @@ enum PassType<'a> {
|
||||||
Random,
|
Random,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to generate all possible filenames of a certain length using NAMESET as an alphabet
|
// Used to generate all possible filenames of a certain length using NAME_CHARSET as an alphabet
|
||||||
struct FilenameGenerator {
|
struct FilenameGenerator {
|
||||||
name_len: usize,
|
name_len: usize,
|
||||||
nameset_indices: RefCell<Vec<usize>>, // Store the indices of the letters of our filename in NAMESET
|
name_charset_indices: RefCell<Vec<usize>>, // Store the indices of the letters of our filename in NAME_CHARSET
|
||||||
exhausted: Cell<bool>,
|
exhausted: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ impl FilenameGenerator {
|
||||||
let indices: Vec<usize> = vec![0; name_len];
|
let indices: Vec<usize> = vec![0; name_len];
|
||||||
FilenameGenerator {
|
FilenameGenerator {
|
||||||
name_len,
|
name_len,
|
||||||
nameset_indices: RefCell::new(indices),
|
name_charset_indices: RefCell::new(indices),
|
||||||
exhausted: Cell::new(false),
|
exhausted: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,25 +85,25 @@ impl Iterator for FilenameGenerator {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut nameset_indices = self.nameset_indices.borrow_mut();
|
let mut name_charset_indices = self.name_charset_indices.borrow_mut();
|
||||||
|
|
||||||
// Make the return value, then increment
|
// Make the return value, then increment
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
for i in nameset_indices.iter() {
|
for i in name_charset_indices.iter() {
|
||||||
let c: char = NAMESET.chars().nth(*i).unwrap();
|
let c: char = NAME_CHARSET.chars().nth(*i).unwrap();
|
||||||
ret.push(c);
|
ret.push(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if nameset_indices[0] == NAMESET.len() - 1 {
|
if name_charset_indices[0] == NAME_CHARSET.len() - 1 {
|
||||||
self.exhausted.set(true)
|
self.exhausted.set(true)
|
||||||
}
|
}
|
||||||
// Now increment the least significant index
|
// Now increment the least significant index
|
||||||
for i in (0..self.name_len).rev() {
|
for i in (0..self.name_len).rev() {
|
||||||
if nameset_indices[i] == NAMESET.len() - 1 {
|
if name_charset_indices[i] == NAME_CHARSET.len() - 1 {
|
||||||
nameset_indices[i] = 0; // Carry the 1
|
name_charset_indices[i] = 0; // Carry the 1
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
nameset_indices[i] += 1;
|
name_charset_indices[i] += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ static AFTER_HELP: &str =
|
||||||
assumption. The following are examples of file systems on which shred is\n\
|
assumption. The following are examples of file systems on which shred is\n\
|
||||||
not effective, or is not guaranteed to be effective in all file system modes:\n\
|
not effective, or is not guaranteed to be effective in all file system modes:\n\
|
||||||
\n\
|
\n\
|
||||||
* log-structured or journaled file systems, such as those supplied with\n\
|
* log-structured or journal file systems, such as those supplied with\n\
|
||||||
AIX and Solaris (and JFS, ReiserFS, XFS, Ext3, etc.)\n\
|
AIX and Solaris (and JFS, ReiserFS, XFS, Ext3, etc.)\n\
|
||||||
\n\
|
\n\
|
||||||
* file systems that write redundant data and carry on even if some writes\n\
|
* file systems that write redundant data and carry on even if some writes\n\
|
||||||
|
@ -250,7 +250,7 @@ static AFTER_HELP: &str =
|
||||||
and shred is thus of limited effectiveness) only in data=journal mode,\n\
|
and shred is thus of limited effectiveness) only in data=journal mode,\n\
|
||||||
which journals file data in addition to just metadata. In both the\n\
|
which journals file data in addition to just metadata. In both the\n\
|
||||||
data=ordered (default) and data=writeback modes, shred works as usual.\n\
|
data=ordered (default) and data=writeback modes, shred works as usual.\n\
|
||||||
Ext3 journaling modes can be changed by adding the data=something option\n\
|
Ext3 journal modes can be changed by adding the data=something option\n\
|
||||||
to the mount options for a particular file system in the /etc/fstab file,\n\
|
to the mount options for a particular file system in the /etc/fstab file,\n\
|
||||||
as documented in the mount man page (man mount).\n\
|
as documented in the mount man page (man mount).\n\
|
||||||
\n\
|
\n\
|
||||||
|
@ -412,7 +412,7 @@ fn get_size(size_str_opt: Option<String>) -> Option<u64> {
|
||||||
_ => 1u64,
|
_ => 1u64,
|
||||||
};
|
};
|
||||||
|
|
||||||
let coeff = match size_str.parse::<u64>() {
|
let coefficient = match size_str.parse::<u64>() {
|
||||||
Ok(u) => u,
|
Ok(u) => u,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{}: {}: Invalid file size", NAME, size_str_opt.unwrap());
|
println!("{}: {}: Invalid file size", NAME, size_str_opt.unwrap());
|
||||||
|
@ -420,7 +420,7 @@ fn get_size(size_str_opt: Option<String>) -> Option<u64> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(coeff * unit)
|
Some(coefficient * unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pass_name(pass_type: PassType) -> String {
|
fn pass_name(pass_type: PassType) -> String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue