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
13 changes: 13 additions & 0 deletions src/main/java/com/rarchives/ripme/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.rarchives.ripme.ui.MainWindow;
import com.rarchives.ripme.ui.UpdateUtils;
import com.rarchives.ripme.utils.Proxy;
import com.rarchives.ripme.utils.RipStatus;
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;

Expand Down Expand Up @@ -186,6 +187,10 @@ private static void handleArguments(String[] args) throws IOException {
System.exit(-1);
}
for (HistoryEntry entry : HISTORY.toList()) {
if (RipStatus.consumePanicAll()) {
logger.error("[!] Cancelling the rest of the re-rip queue (device.nospace or similar)");
break;
}
try {
URL url = new URI(entry.url).toURL();
rip(url);
Expand Down Expand Up @@ -213,6 +218,10 @@ private static void handleArguments(String[] args) throws IOException {
}
int added = 0;
for (HistoryEntry entry : HISTORY.toList()) {
if (RipStatus.consumePanicAll()) {
logger.error("[!] Cancelling the rest of the re-rip queue (device.nospace or similar)");
break;
}
if (entry.selected) {
added++;
try {
Expand Down Expand Up @@ -260,6 +269,10 @@ private static void handleArguments(String[] args) throws IOException {
try (BufferedReader br = Files.newBufferedReader(urlfile)) {
String url;
while ((url = br.readLine()) != null) {
if (RipStatus.consumePanicAll()) {
logger.error("[!] Cancelling the rest of the URLs in " + urlfile + " (device.nospace or similar)");
break;
}
if (url.startsWith("//") || url.startsWith("#")) {
logger.debug("Skipping over line \"" + url + "\"because it is a comment");
} else {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jsoup.HttpStatusException;

import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.RipStatus;
import com.rarchives.ripme.utils.Utils;

/**
Expand Down Expand Up @@ -346,7 +347,15 @@ public void run() {
} catch (IOException e) {
if (guessIsENOSPC(e, saveAs)) {
logger.debug("IOException", e);
observer.downloadErrored(ripUrlId, Utils.getLocalizedString("device.nospace")); // TODO cancel all rips
logger.error("[!] Device is out of space, cancelling the rest of this album and the queue");
observer.downloadErrored(ripUrlId, Utils.getLocalizedString("device.nospace"));
// Disk-full is systemic, not specific to this one download: stop the
// rest of the current album immediately (this mechanism already
// existed), and signal that the rest of the queue should be
// cancelled too, whether we're running under the GUI or a headless
// CLI batch rip (-r/-R/-f).
observer.panic();
RipStatus.requestPanicAll();
return;
}
logger.debug("IOException", e);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/rarchives/ripme/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import com.rarchives.ripme.ripper.AbstractRipper;
import com.rarchives.ripme.uiUtils.ContextActionProtections;
import com.rarchives.ripme.utils.RipStatus;
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.TransferRate;
import com.rarchives.ripme.utils.Utils;
Expand Down Expand Up @@ -1358,6 +1359,14 @@ private void ripNextAlbum() {
return;
}

if (RipStatus.consumePanicAll()) {
// A download thread hit a disk-full error and asked for the rest
// of the queue to be cancelled too (see RipStatus).
LOGGER.debug("panicAll requested - cancelling the rest of the queue");
ripFinishCleanup();
return;
}

if (queueListModel.isEmpty()) {
// End of queue
ripFinishCleanup();
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/rarchives/ripme/utils/RipStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.rarchives.ripme.utils;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Process-wide "stop everything" signal, used to cancel the rest of the rip
* queue (e.g. when a download fails because the disk is full).
* <p>
* This is intentionally a tiny, Swing-free holder rather than a field on
* {@code MainWindow}. Code that may run with no GUI at all - such as
* {@code DownloadFileThread} during a headless/CLI batch rip
* ({@code -r}/{@code -R}/{@code -f}) - must be able to request a queue-wide
* stop without touching {@code MainWindow}: merely referencing that class
* triggers its static Swing field initializers and can throw a
* {@code HeadlessException} when there is no display.
*/
public class RipStatus {

private static final AtomicBoolean panicAll = new AtomicBoolean(false);

private RipStatus() { }

/**
* Requests that all remaining work - the rest of the current album plus
* anything still queued - be cancelled.
*/
public static void requestPanicAll() {
panicAll.set(true);
}

/**
* Returns whether a queue-wide panic was requested, and resets the flag.
* Consuming the flag (rather than just peeking at it) ensures a disk-full
* panic from one rip session doesn't leak into the next, unrelated one.
*
* @return true if {@link #requestPanicAll()} was called since the last
* time this method was called.
*/
public static boolean consumePanicAll() {
return panicAll.getAndSet(false);
}
}
38 changes: 38 additions & 0 deletions src/test/java/com/rarchives/ripme/utils/RipStatusTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.rarchives.ripme.utils;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class RipStatusTest {

@AfterEach
public void resetFlag() {
// RipStatus holds process-wide state; make sure one test's panic
// request can't leak into the next test.
RipStatus.consumePanicAll();
}

@Test
public void consumePanicAllIsFalseByDefault() {
Assertions.assertFalse(RipStatus.consumePanicAll());
}

@Test
public void consumePanicAllReturnsTrueAfterRequest() {
RipStatus.requestPanicAll();
Assertions.assertTrue(RipStatus.consumePanicAll());
}

@Test
public void consumePanicAllResetsAfterBeingRead() {
RipStatus.requestPanicAll();

Assertions.assertTrue(RipStatus.consumePanicAll());
// A second read, with no new request in between, must not see the
// same panic again - otherwise a disk-full panic from one rip
// session would leak into the next, unrelated one.
Assertions.assertFalse(RipStatus.consumePanicAll());
}

}