Skip to content

Commit

Permalink
shred: fix permissions_set_readonly_false clippy error
Browse files Browse the repository at this point in the history
  • Loading branch information
miles170 committed Mar 10, 2023
1 parent cf68665 commit c4cce9f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/uu/shred/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.

// spell-checker:ignore (words) writeback wipesync
// spell-checker:ignore (words) writeback wipesync IWRITE

use clap::{crate_version, Arg, ArgAction, Command};
use rand::prelude::SliceRandom;
Expand All @@ -16,9 +16,13 @@ use std::fs;
use std::fs::{File, OpenOptions};
use std::io;
use std::io::prelude::*;
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
#[cfg(target_family = "unix")]
use uucore::libc::S_IWRITE;
use uucore::{format_usage, show, show_if_err, util_name};

const BLOCK_SIZE: usize = 512;
Expand Down Expand Up @@ -462,6 +466,14 @@ fn wipe_file(
if force {
let metadata = fs::metadata(path).map_err_context(String::new)?;
let mut perms = metadata.permissions();
#[cfg(target_family = "unix")]
// NOTE: set_readonly(false) makes the file world-writable on Unix.
#[allow(clippy::unnecessary_cast)]
// NOTE: S_IWRITE type is u16 on macOS.
perms.set_mode(perms.mode() | (S_IWRITE as u32));
#[cfg(not(target_family = "unix"))]
#[allow(clippy::permissions_set_readonly_false)]
// FIXME: Clippy still throws error on non-UNIX platforms.
perms.set_readonly(false);
fs::set_permissions(path, perms).map_err_context(String::new)?;
}
Expand Down

0 comments on commit c4cce9f

Please sign in to comment.