mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-04 19:48:54 +01:00
120 lines
4.1 KiB
Java
120 lines
4.1 KiB
Java
package org.apache.commons.io;
|
|
|
|
import defpackage.a$$ExternalSyntheticOutline0;
|
|
import java.io.File;
|
|
import java.lang.ref.PhantomReference;
|
|
import java.lang.ref.ReferenceQueue;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes10.dex */
|
|
public class FileCleaningTracker {
|
|
volatile boolean exitWhenFinished;
|
|
Thread reaper;
|
|
ReferenceQueue<Object> q = new ReferenceQueue<>();
|
|
final Collection<Tracker> trackers = a$$ExternalSyntheticOutline0.m();
|
|
final List<String> deleteFailures = Collections.synchronizedList(new ArrayList());
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public final class Reaper extends Thread {
|
|
public Reaper() {
|
|
super("File Reaper");
|
|
setPriority(10);
|
|
setDaemon(true);
|
|
}
|
|
|
|
@Override // java.lang.Thread, java.lang.Runnable
|
|
public void run() {
|
|
while (true) {
|
|
if (FileCleaningTracker.this.exitWhenFinished && FileCleaningTracker.this.trackers.isEmpty()) {
|
|
return;
|
|
}
|
|
try {
|
|
Tracker tracker = (Tracker) FileCleaningTracker.this.q.remove();
|
|
FileCleaningTracker.this.trackers.remove(tracker);
|
|
if (!tracker.delete()) {
|
|
FileCleaningTracker.this.deleteFailures.add(tracker.getPath());
|
|
}
|
|
tracker.clear();
|
|
} catch (InterruptedException unused) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static final class Tracker extends PhantomReference<Object> {
|
|
private final FileDeleteStrategy deleteStrategy;
|
|
private final String path;
|
|
|
|
public Tracker(String str, FileDeleteStrategy fileDeleteStrategy, Object obj, ReferenceQueue<? super Object> referenceQueue) {
|
|
super(obj, referenceQueue);
|
|
this.path = str;
|
|
this.deleteStrategy = fileDeleteStrategy == null ? FileDeleteStrategy.NORMAL : fileDeleteStrategy;
|
|
}
|
|
|
|
public boolean delete() {
|
|
return this.deleteStrategy.deleteQuietly(new File(this.path));
|
|
}
|
|
|
|
public String getPath() {
|
|
return this.path;
|
|
}
|
|
}
|
|
|
|
private synchronized void addTracker(String str, Object obj, FileDeleteStrategy fileDeleteStrategy) {
|
|
try {
|
|
if (this.exitWhenFinished) {
|
|
throw new IllegalStateException("No new trackers can be added once exitWhenFinished() is called");
|
|
}
|
|
if (this.reaper == null) {
|
|
Reaper reaper = new Reaper();
|
|
this.reaper = reaper;
|
|
reaper.start();
|
|
}
|
|
this.trackers.add(new Tracker(str, fileDeleteStrategy, obj, this.q));
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public synchronized void exitWhenFinished() {
|
|
this.exitWhenFinished = true;
|
|
Thread thread = this.reaper;
|
|
if (thread != null) {
|
|
synchronized (thread) {
|
|
this.reaper.interrupt();
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<String> getDeleteFailures() {
|
|
return this.deleteFailures;
|
|
}
|
|
|
|
public int getTrackCount() {
|
|
return this.trackers.size();
|
|
}
|
|
|
|
public void track(File file, Object obj, FileDeleteStrategy fileDeleteStrategy) {
|
|
Objects.requireNonNull(file, "file");
|
|
addTracker(file.getPath(), obj, fileDeleteStrategy);
|
|
}
|
|
|
|
public void track(File file, Object obj) {
|
|
track(file, obj, (FileDeleteStrategy) null);
|
|
}
|
|
|
|
public void track(String str, Object obj) {
|
|
track(str, obj, (FileDeleteStrategy) null);
|
|
}
|
|
|
|
public void track(String str, Object obj, FileDeleteStrategy fileDeleteStrategy) {
|
|
Objects.requireNonNull(str, "path");
|
|
addTracker(str, obj, fileDeleteStrategy);
|
|
}
|
|
}
|