package p5;

import androidx.navigation.C1134i;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import x4.AbstractC3256v;

/* JADX INFO: loaded from: classes3.dex */
public class B extends AbstractC2749t {
    public static ArrayList a(G g6, boolean z6) throws IOException {
        File fileG = g6.g();
        String[] list = fileG.list();
        if (list == null) {
            if (!z6) {
                return null;
            }
            if (fileG.exists()) {
                throw new IOException(com.google.android.recaptcha.internal.a.p(g6, "failed to list "));
            }
            throw new FileNotFoundException(com.google.android.recaptcha.internal.a.p(g6, "no such file: "));
        }
        ArrayList arrayList = new ArrayList();
        for (String str : list) {
            kotlin.jvm.internal.o.e(str);
            arrayList.add(g6.e(str));
        }
        AbstractC3256v.I(arrayList);
        return arrayList;
    }

    @Override // p5.AbstractC2749t
    public N appendingSink(G file, boolean z6) throws IOException {
        kotlin.jvm.internal.o.h(file, "file");
        if (!z6 || exists(file)) {
            File fileG = file.g();
            Logger logger = E.f23044a;
            return AbstractC2732b.h(new FileOutputStream(fileG, true));
        }
        throw new IOException(file + " doesn't exist.");
    }

    @Override // p5.AbstractC2749t
    public void atomicMove(G source, G target) throws IOException {
        kotlin.jvm.internal.o.h(source, "source");
        kotlin.jvm.internal.o.h(target, "target");
        if (source.g().renameTo(target.g())) {
            return;
        }
        throw new IOException("failed to move " + source + " to " + target);
    }

    @Override // p5.AbstractC2749t
    public G canonicalize(G path) throws IOException {
        kotlin.jvm.internal.o.h(path, "path");
        File canonicalFile = path.g().getCanonicalFile();
        if (!canonicalFile.exists()) {
            throw new FileNotFoundException("no such file");
        }
        String str = G.f23047b;
        return C1134i.p(canonicalFile);
    }

    @Override // p5.AbstractC2749t
    public void createDirectory(G dir, boolean z6) throws IOException {
        kotlin.jvm.internal.o.h(dir, "dir");
        if (dir.g().mkdir()) {
            return;
        }
        r rVarMetadataOrNull = metadataOrNull(dir);
        if (rVarMetadataOrNull == null || !rVarMetadataOrNull.f23116b) {
            throw new IOException(com.google.android.recaptcha.internal.a.p(dir, "failed to create directory: "));
        }
        if (z6) {
            throw new IOException(dir + " already exists.");
        }
    }

    @Override // p5.AbstractC2749t
    public void createSymlink(G source, G target) throws IOException {
        kotlin.jvm.internal.o.h(source, "source");
        kotlin.jvm.internal.o.h(target, "target");
        throw new IOException("unsupported");
    }

    @Override // p5.AbstractC2749t
    public void delete(G path, boolean z6) throws IOException {
        kotlin.jvm.internal.o.h(path, "path");
        if (Thread.interrupted()) {
            throw new InterruptedIOException("interrupted");
        }
        File fileG = path.g();
        if (fileG.delete()) {
            return;
        }
        if (fileG.exists()) {
            throw new IOException(com.google.android.recaptcha.internal.a.p(path, "failed to delete "));
        }
        if (z6) {
            throw new FileNotFoundException(com.google.android.recaptcha.internal.a.p(path, "no such file: "));
        }
    }

    @Override // p5.AbstractC2749t
    public List list(G dir) throws IOException {
        kotlin.jvm.internal.o.h(dir, "dir");
        ArrayList arrayListA = a(dir, true);
        kotlin.jvm.internal.o.e(arrayListA);
        return arrayListA;
    }

    @Override // p5.AbstractC2749t
    public List listOrNull(G dir) {
        kotlin.jvm.internal.o.h(dir, "dir");
        return a(dir, false);
    }

    @Override // p5.AbstractC2749t
    public r metadataOrNull(G path) {
        kotlin.jvm.internal.o.h(path, "path");
        File fileG = path.g();
        boolean zIsFile = fileG.isFile();
        boolean zIsDirectory = fileG.isDirectory();
        long jLastModified = fileG.lastModified();
        long length = fileG.length();
        if (!zIsFile && !zIsDirectory && jLastModified == 0 && length == 0 && !fileG.exists()) {
            return null;
        }
        return new r(zIsFile, zIsDirectory, null, Long.valueOf(length), null, Long.valueOf(jLastModified), null);
    }

    @Override // p5.AbstractC2749t
    public AbstractC2747q openReadOnly(G file) {
        kotlin.jvm.internal.o.h(file, "file");
        return new A(false, new RandomAccessFile(file.g(), "r"), 0);
    }

    @Override // p5.AbstractC2749t
    public AbstractC2747q openReadWrite(G file, boolean z6, boolean z7) throws IOException {
        kotlin.jvm.internal.o.h(file, "file");
        if (z6 && z7) {
            throw new IllegalArgumentException("Cannot require mustCreate and mustExist at the same time.");
        }
        if (z6 && exists(file)) {
            throw new IOException(file + " already exists.");
        }
        if (!z7 || exists(file)) {
            return new A(true, new RandomAccessFile(file.g(), "rw"), 0);
        }
        throw new IOException(file + " doesn't exist.");
    }

    @Override // p5.AbstractC2749t
    public N sink(G file, boolean z6) throws IOException {
        kotlin.jvm.internal.o.h(file, "file");
        if (!z6 || !exists(file)) {
            File fileG = file.g();
            Logger logger = E.f23044a;
            return AbstractC2732b.h(new FileOutputStream(fileG, false));
        }
        throw new IOException(file + " already exists.");
    }

    @Override // p5.AbstractC2749t
    public P source(G file) {
        kotlin.jvm.internal.o.h(file, "file");
        return AbstractC2732b.j(file.g());
    }

    public String toString() {
        return "JvmSystemFileSystem";
    }
}
