mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-14 21:42:19 +00:00
Meta: Remove shred utility
This commit is contained in:
parent
d61770c457
commit
aef6ece9e6
Notes:
sideshowbarker
2024-07-16 20:21:48 +09:00
Author: https://github.com/ADKaster
Commit: aef6ece9e6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/81
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 0 additions and 115 deletions
|
@ -1,39 +0,0 @@
|
||||||
## Name
|
|
||||||
|
|
||||||
shred - destroy a file with its content on disk
|
|
||||||
|
|
||||||
## Synopsis
|
|
||||||
|
|
||||||
```**sh
|
|
||||||
$ shred [options...] [path...]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
`shred` destroys files' content on disk.
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
* `--help`: Display this message
|
|
||||||
* `-v`, `--verbose`: Show progress during the shred operation
|
|
||||||
* `-n`, `--iterations`: Iterations count of shred operation
|
|
||||||
* `-u`: Deallocate and remove file after overwriting
|
|
||||||
* `--random-source`: Get random bytes from a file other than /dev/random
|
|
||||||
|
|
||||||
## Arguments
|
|
||||||
|
|
||||||
* `path`: Files to shred
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# shred a file and remove it aftewards
|
|
||||||
$ shred -u /tmp/FILE_TO_BE_SHREDDED_AND_REMOVED
|
|
||||||
# shred a file with 10 iterations
|
|
||||||
$ shred --iterations 10 /tmp/FILE_TO_BE_SHREDDED
|
|
||||||
# shred a file with verbose progress and 10 iterations
|
|
||||||
$ shred -v --iterations 10 /tmp/FILE_TO_BE_SHREDDED
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
* [`rm`(1)](help://man/1/rm) to delete a file or directory without overwriting the content first
|
|
|
@ -9,7 +9,6 @@ set(CMD_SOURCES
|
||||||
isobmff.cpp
|
isobmff.cpp
|
||||||
js.cpp
|
js.cpp
|
||||||
lzcat.cpp
|
lzcat.cpp
|
||||||
shred.cpp
|
|
||||||
tar.cpp
|
tar.cpp
|
||||||
test-jpeg-roundtrip.cpp
|
test-jpeg-roundtrip.cpp
|
||||||
ttfdisasm.cpp
|
ttfdisasm.cpp
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024, Romain Chardiny <romain.chardiny@gmail.com>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
|
||||||
#include <LibCore/File.h>
|
|
||||||
#include <LibCore/System.h>
|
|
||||||
#include <LibFileSystem/FileSystem.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
||||||
{
|
|
||||||
TRY(Core::System::pledge("stdio unix rpath wpath cpath"));
|
|
||||||
|
|
||||||
Vector<StringView> paths;
|
|
||||||
bool remove_file = false;
|
|
||||||
bool verbose = false;
|
|
||||||
u32 iterations = 3;
|
|
||||||
Optional<StringView> random_source;
|
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
|
||||||
args_parser.add_option(remove_file, "Deallocate and remove file after overwriting", nullptr, 'u');
|
|
||||||
args_parser.add_option(verbose, "Show progress", "verbose", 'v');
|
|
||||||
args_parser.add_option(iterations, "Overwrite N times instead of the default (3)", "iterations", 'n', "N");
|
|
||||||
args_parser.add_option(random_source, "Get random bytes from FILE", "random-source", 0, "FILE");
|
|
||||||
args_parser.add_positional_argument(paths, "Path(s) to overwrite", "FILE", Core::ArgsParser::Required::Yes);
|
|
||||||
args_parser.parse(arguments);
|
|
||||||
|
|
||||||
auto rng_file = TRY(Core::File::open(random_source.value_or("/dev/random"sv), Core::File::OpenMode::Read));
|
|
||||||
|
|
||||||
for (auto& path : paths) {
|
|
||||||
auto file = TRY(Core::File::open(path, Core::File::OpenMode::ReadWrite | Core::File::OpenMode::DontCreate));
|
|
||||||
|
|
||||||
off_t output_file_length = TRY(FileSystem::size_from_fstat(file->fd()));
|
|
||||||
|
|
||||||
for (u32 iter = 0; iter < iterations; iter++) {
|
|
||||||
if (verbose)
|
|
||||||
outln("shred: {}: pass {}/{} (random)", path, iter + 1, iterations);
|
|
||||||
|
|
||||||
Array<u8, BUFSIZ> buffer;
|
|
||||||
off_t total_written = 0;
|
|
||||||
ssize_t nread = 0;
|
|
||||||
ssize_t nwritten = 0;
|
|
||||||
|
|
||||||
while (total_written < output_file_length) {
|
|
||||||
auto buffer_span = buffer.span().trim(output_file_length - total_written);
|
|
||||||
|
|
||||||
nread = TRY(Core::System::read(rng_file->fd(), buffer_span));
|
|
||||||
|
|
||||||
if (nread == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
nwritten = TRY(Core::System::write(file->fd(), buffer_span));
|
|
||||||
|
|
||||||
if (nwritten == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
total_written += nwritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRY(Core::System::fsync(file->fd()));
|
|
||||||
TRY(file->seek(0, SeekMode::SetPosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remove_file) {
|
|
||||||
TRY(Core::System::ftruncate(file->fd(), 0));
|
|
||||||
TRY(Core::System::unlink(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue