Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ nb-configuration.xml
# JRebel
rebel-remote.xml
rebel.xml
*.log
logs/
27 changes: 27 additions & 0 deletions src/main/java/org/flossware/diskwipe/CleanDisk.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@
* @author Scot P. Floess
*/
public class CleanDisk {
/**
* Immutable set of filesystem paths that are considered unsafe targets for disk wiping operations.
* Any wipe request targeting one of these paths, or a subdirectory beneath one, is rejected
* by {@link #validateSafeDirectory(String)} with an {@link IllegalArgumentException}.
*
* <p>The set includes critical system directories for both Unix-like operating systems
* ({@code /}, {@code /bin}, {@code /boot}, {@code /dev}, {@code /etc}, {@code /lib},
* {@code /lib64}, {@code /proc}, {@code /root}, {@code /sbin}, {@code /sys}, {@code /usr},
* {@code /var}, {@code /home}) and macOS/Windows ({@code /Users}, {@code C:\},
* {@code C:\Windows}, {@code C:\Program Files}).</p>
*
* <p><strong>WARNING:</strong> Removing or modifying entries in this set weakens the safety
* guard and may allow the wipe utility to destroy an operating system installation.
* Additions to this set are encouraged when deploying to environments with additional
* protected mount points.</p>
*
* <p>Usage example (internal, via {@code validateSafeDirectory}):</p>
* <pre>{@code
* // This call succeeds because /tmp/wipe is not in DANGEROUS_PATHS:
* CleanDisk.validateSafeDirectory("/tmp/wipe");
*
* // This call throws IllegalArgumentException because "/" is dangerous:
* CleanDisk.validateSafeDirectory("/");
* }</pre>
*
* @see #validateSafeDirectory(String)
*/
private static final Set<String> DANGEROUS_PATHS = new HashSet<>(Arrays.asList(
"/", "/bin", "/boot", "/dev", "/etc", "/lib", "/lib64",
"/proc", "/root", "/sbin", "/sys", "/usr", "/var",
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/flossware/diskwipe/WipeConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
* @author Scot P. Floess
*/
class WipeConfiguration {
/**
* The default number of worker threads used for disk wipe operations when no explicit
* thread count is provided via {@link Builder#threadCount(int)}.
*
* <p>This value (4) provides a reasonable balance between parallelism and resource
* consumption on most modern multi-core systems. It is used as the initial value
* in {@link Builder} and applied whenever the caller does not override it.</p>
*
* <p><strong>Usage example:</strong></p>
* <pre>
* // Uses DEFAULT_THREAD_COUNT (4) since threadCount is not set:
* WipeConfiguration config = new WipeConfiguration.Builder().build();
* assert config.getThreadCount() == 4;
*
* // Override the default:
* WipeConfiguration custom = new WipeConfiguration.Builder()
* .threadCount(8)
* .build();
* </pre>
*
* @see Builder#threadCount(int)
* @see #getThreadCount()
*/
private static final int DEFAULT_THREAD_COUNT = 4;
private static final int DEFAULT_BUFFER_SIZE = 10 * 1024 * 1024; // 10MB

Expand Down Expand Up @@ -81,6 +104,26 @@ public boolean isSkipConfirmation() {
return skipConfirmation;
}

/**
* Returns a human-readable string representation of this wipe configuration,
* summarizing the thread count, buffer size in bytes, and skip confirmation flag.
*
* <p>The returned format is:
* {@code WipeConfiguration{threads=N, bufferSize=N bytes, skipConfirmation=true|false}}</p>
*
* <p><strong>Usage example:</strong></p>
* <pre>
* WipeConfiguration config = new WipeConfiguration.Builder()
* .threadCount(8)
* .bufferSize(20 * 1024 * 1024)
* .build();
* System.out.println(config);
* // Output: WipeConfiguration{threads=8, bufferSize=20971520 bytes, skipConfirmation=false}
* </pre>
*
* @return a formatted string containing the thread count, buffer size (in bytes),
* and confirmation skip flag
*/
@Override
public String toString() {
return String.format("WipeConfiguration{threads=%d, bufferSize=%d bytes, skipConfirmation=%s}",
Expand Down
Loading
Loading