2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Use FileUtils.directoryContains().

This commit is contained in:
Isira Seneviratne
2020-07-12 19:31:50 +05:30
committed by Nicolas Fella
parent 4a4147bd4d
commit 2f386ff5c0

View File

@@ -22,7 +22,9 @@ package org.kde.kdeconnect.Plugins.SftpPlugin;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.apache.commons.io.FileUtils;
import org.apache.sshd.common.file.nativefs.NativeSshFile; import org.apache.sshd.common.file.nativefs.NativeSshFile;
import org.kde.kdeconnect.Helpers.MediaStoreHelper; import org.kde.kdeconnect.Helpers.MediaStoreHelper;
@@ -33,7 +35,7 @@ import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
class AndroidSshFile extends NativeSshFile { class AndroidSshFile extends NativeSshFile {
private final static String TAG = AndroidSshFile.class.getSimpleName(); private static final String TAG = AndroidSshFile.class.getSimpleName();
final private Context context; final private Context context;
final private File file; final private File file;
@@ -97,15 +99,11 @@ class AndroidSshFile extends NativeSshFile {
if (!exists) { if (!exists) {
// file.exists() returns false when we don't have read permission // file.exists() returns false when we don't have read permission
// try to figure out if it really does not exist // try to figure out if it really does not exist
File parentFile = file.getParentFile(); try {
File[] children = parentFile.listFiles(); exists = FileUtils.directoryContains(file.getParentFile(), file);
if (children != null) { } catch (IOException | IllegalArgumentException e) {
for (File child : children) { // An IllegalArgumentException is thrown if the parent is null or not a directory.
if (file.equals(child)) { Log.d(TAG, "Exception: ", e);
exists = true;
break;
}
}
} }
} }