From 4620cdfa8ffffcd790fce7c08501e984224810de Mon Sep 17 00:00:00 2001 From: EmmanuelMess Date: Thu, 27 Jan 2022 21:40:17 -0300 Subject: [PATCH] Implementation for DocumentFileAmazeFilesystem --- .../filemanager/filesystem/HybridFile.java | 153 +++---------- .../files/DocumentFileAmazeFilesystem.kt | 212 ++++++++++++++++++ .../filesystem/otg/OtgAmazeFilesystem.kt | 17 +- .../filesystem/ssh/SshAmazeFilesystem.java | 14 +- .../filesystem/filetypes/AmazeFile.kt | 8 - .../filesystem/filetypes/AmazeFilesystem.kt | 6 +- .../filetypes/cloud/CloudAmazeFilesystem.kt | 8 +- .../filetypes/file/FileAmazeFilesystem.kt | 11 +- .../filetypes/smb/SmbAmazeFilesystem.kt | 8 +- 9 files changed, 264 insertions(+), 173 deletions(-) create mode 100644 app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java index 8200248c9e..8f31f61b37 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java @@ -49,6 +49,7 @@ import com.amaze.filemanager.file_operations.filesystem.filetypes.cloud.onedrive.OnedriveAccount; import com.amaze.filemanager.file_operations.filesystem.root.NativeOperations; import com.amaze.filemanager.filesystem.cloud.CloudUtil; +import com.amaze.filemanager.filesystem.files.DocumentFileAmazeFilesystem; import com.amaze.filemanager.filesystem.files.FileUtils; import com.amaze.filemanager.filesystem.root.DeleteFileCommand; import com.amaze.filemanager.filesystem.root.ListFilesCommand; @@ -96,9 +97,6 @@ public class HybridFile { protected static final String TAG = HybridFile.class.getSimpleName(); - public static final String DOCUMENT_FILE_PREFIX = - "content://com.android.externalstorage.documents"; - protected String path; protected OpenMode mode; protected String name; @@ -136,7 +134,7 @@ public void generateMode(Context context) { mode = OpenMode.SFTP; } else if (path.startsWith(OTGUtil.PREFIX_OTG)) { mode = OpenMode.OTG; - } else if (path.startsWith(DOCUMENT_FILE_PREFIX)) { + } else if (path.startsWith(DocumentFileAmazeFilesystem.DOCUMENT_FILE_PREFIX)) { mode = OpenMode.DOCUMENT_FILE; } else if (isCustomPath()) { mode = OpenMode.CUSTOM; @@ -260,9 +258,12 @@ public long lastModified() { case SFTP: case SMB: case FILE: - return new AmazeFile(path).lastModified(); case DOCUMENT_FILE: - return getDocumentFile(false).lastModified(); + case BOX: + case DROPBOX: + case GDRIVE: + case ONEDRIVE: + return new AmazeFile(path).lastModified(); case ROOT: HybridFileParcelable baseFile = generateBaseFileFromParent(); if (baseFile != null) return baseFile.getDate(); @@ -282,6 +283,7 @@ public long length(Context context) { case ONEDRIVE: case GDRIVE: case OTG: + case DOCUMENT_FILE: try { return new AmazeFile(path).length(() -> context); } catch (IOException e) { @@ -291,9 +293,6 @@ public long length(Context context) { HybridFileParcelable baseFile = generateBaseFileFromParent(); if (baseFile != null) return baseFile.getSize(); break; - case DOCUMENT_FILE: - s = getDocumentFile(false).length(); - break; default: break; } @@ -310,6 +309,12 @@ public String getSimpleName() { case SFTP: case SMB: case FILE: + case ONEDRIVE: + case GDRIVE: + case DROPBOX: + case BOX: + case OTG: + case DOCUMENT_FILE: return new AmazeFile(path).getName(); default: StringBuilder builder = new StringBuilder(path); @@ -327,16 +332,11 @@ public String getName(Context context) { case ONEDRIVE: case GDRIVE: case OTG: + case SFTP: + case DOCUMENT_FILE: return new AmazeFile(path).getName(); case ROOT: return getFile().getName(); - case DOCUMENT_FILE: - if (!Utils.isNullOrEmpty(name)) { - return name; - } - return OTGUtil.getDocumentFile( - path, SafRootHolder.getUriRoot(), context, OpenMode.DOCUMENT_FILE, false) - .getName(); default: if (path.isEmpty()) { return ""; @@ -375,6 +375,7 @@ public String getParent(Context context) { case GDRIVE: case SFTP: case OTG: + case DOCUMENT_FILE: return new AmazeFile(path).getParent(); default: if (path.length() == getName(context).length()) { @@ -397,7 +398,6 @@ public boolean isDirectory() { boolean isDirectory; switch (mode) { case SFTP: - return isDirectory(AppConfig.getInstance()); case SMB: case FILE: case DROPBOX: @@ -405,7 +405,8 @@ public boolean isDirectory() { case ONEDRIVE: case GDRIVE: case OTG: - return new AmazeFile(path).isDirectory(() -> null); + case DOCUMENT_FILE: + return new AmazeFile(path).isDirectory(AppConfig::getInstance); case ROOT: isDirectory = NativeOperations.isDirectory(path); break; @@ -420,32 +421,6 @@ public boolean isDirectory(Context context) { boolean isDirectory; switch (mode) { case SFTP: - final Boolean returnValue = - SshClientUtils.execute( - new SFtpClientTemplate(path) { - @Override - public Boolean execute(SFTPClient client) { - try { - return client - .stat(SshClientUtils.extractRemotePathFrom(path)) - .getType() - .equals(FileMode.Type.DIRECTORY); - } catch (IOException notFound) { - Log.e( - getClass().getSimpleName(), - "Fail to execute isDirectory for SFTP path :" + path, - notFound); - return false; - } - } - }); - - if (returnValue == null) { - Log.e(TAG, "Error obtaining if path is directory over SFTP"); - } - - //noinspection SimplifiableConditionalExpression - return returnValue == null ? false : returnValue; case SMB: case FILE: case DROPBOX: @@ -453,13 +428,11 @@ public Boolean execute(SFTPClient client) { case ONEDRIVE: case GDRIVE: case OTG: + case DOCUMENT_FILE: return new AmazeFile(path).isDirectory(() -> context); case ROOT: isDirectory = NativeOperations.isDirectory(path); break; - case DOCUMENT_FILE: - isDirectory = getDocumentFile(false).isDirectory(); - break; default: isDirectory = getFile().isDirectory(); break; @@ -533,12 +506,9 @@ public long getUsableSpace() { case ONEDRIVE: case GDRIVE: case SFTP: - case OTG: - return new AmazeFile(path).getUsableSpace(); + case OTG: case DOCUMENT_FILE: - size = - FileProperties.getDeviceStorageRemainingSpace(SafRootHolder.INSTANCE.getVolumeLabel()); - break; + return new AmazeFile(path).getUsableSpace(); } return size; } @@ -555,11 +525,9 @@ public long getTotal(Context context) { case ONEDRIVE: case GDRIVE: case SFTP: - case OTG: - return new AmazeFile(path).getTotalSpace(() -> context); + case OTG: case DOCUMENT_FILE: - size = getDocumentFile(false).length(); - break; + return new AmazeFile(path).getTotalSpace(() -> context); } return size; } @@ -747,18 +715,9 @@ public InputStream getInputStream(Context context) { case BOX: case ONEDRIVE: case GDRIVE: - case OTG: - return new AmazeFile(getPath()).getInputStream(() -> context); + case OTG: case DOCUMENT_FILE: - ContentResolver contentResolver = context.getContentResolver(); - DocumentFile documentSourceFile = getDocumentFile(false); - try { - inputStream = contentResolver.openInputStream(documentSourceFile.getUri()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - inputStream = null; - } - break; + return new AmazeFile(getPath()).getInputStream(() -> context); default: try { inputStream = new FileInputStream(path); @@ -783,17 +742,8 @@ public OutputStream getOutputStream(Context context) { case ONEDRIVE: case GDRIVE: case OTG: - return new AmazeFile(path).getOutputStream(() -> context); case DOCUMENT_FILE: - ContentResolver contentResolver = context.getContentResolver(); - DocumentFile documentSourceFile = getDocumentFile(true); - try { - outputStream = contentResolver.openOutputStream(documentSourceFile.getUri()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - outputStream = null; - } - break; + return new AmazeFile(path).getOutputStream(() -> context); default: try { outputStream = FileUtil.getOutputStream(getFile(), context); @@ -806,35 +756,14 @@ public OutputStream getOutputStream(Context context) { } public boolean exists() { - boolean exists = false; - if (isSftp()) { - // TODO use Amaze file - final Boolean executionReturn = - SshClientUtils.execute( - new SFtpClientTemplate(path) { - @Override - public Boolean execute(SFTPClient client) throws IOException { - try { - return client.stat(SshClientUtils.extractRemotePathFrom(path)) != null; - } catch (SFTPException notFound) { - return false; - } - } - }); - - if (executionReturn == null) { - Log.e(TAG, "Error obtaining existance of file over SFTP"); - } - - //noinspection SimplifiableConditionalExpression - exists = executionReturn == null ? false : executionReturn; - } else if (isSmb() || isLocal() || isDropBoxFile() || isBoxFile() || isGoogleDriveFile() || isOneDriveFile()) { + if (isSmb() || isLocal() || isDropBoxFile() || isBoxFile() || isGoogleDriveFile() + || isOneDriveFile() || isDocumentFile() || isSftp()) { return new AmazeFile(path).exists(() -> null); } else if (isRoot()) { return RootHelper.fileExists(path); } - return exists; + return false; } /** Helper method to check file existence in otg */ @@ -842,7 +771,7 @@ public boolean exists(Context context) { boolean exists = false; try { if (isSmb() || isLocal() || isDropBoxFile() || isBoxFile() || isGoogleDriveFile() - || isOneDriveFile() || isOtgFile() || isSftp()) { + || isOneDriveFile() || isOtgFile() || isSftp() || isDocumentFile()) { return new AmazeFile(path).exists(() -> context); } else if (isDocumentFile()) { exists = @@ -878,7 +807,8 @@ public boolean isSimpleFile() { } public boolean setLastModified(final long date) { - if (isSmb() || isLocal() || isOneDriveFile() || isBoxFile() || isGoogleDriveFile() || isDropBoxFile() || isSftp() || isOtgFile()) { + if (isSmb() || isLocal() || isOneDriveFile() || isBoxFile() || isGoogleDriveFile() + || isDropBoxFile() || isSftp() || isOtgFile()) { return new AmazeFile(path).setLastModified(date); } File f = getFile(); @@ -886,21 +816,10 @@ public boolean setLastModified(final long date) { } public void mkdir(Context context) { - if (isSftp() || isSmb() || isLocal() || isRoot() || isCustomPath() || isUnknownFile() || isOneDriveFile() || isBoxFile() || isGoogleDriveFile() || isDropBoxFile() || isOtgFile()) { + if (isSftp() || isSmb() || isLocal() || isRoot() || isCustomPath() || isUnknownFile() + || isOneDriveFile() || isBoxFile() || isGoogleDriveFile() || isDropBoxFile() + || isOtgFile() || isDocumentFile()) { new AmazeFile(path).mkdirs(() -> context); - } else if (isDocumentFile()) { - if (!exists(context)) { - DocumentFile parentDirectory = - OTGUtil.getDocumentFile( - getParent(context), - SafRootHolder.getUriRoot(), - context, - OpenMode.DOCUMENT_FILE, - true); - if (parentDirectory.isDirectory()) { - parentDirectory.createDirectory(getName(context)); - } - } } else { throw new IllegalStateException(); } diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt b/app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt new file mode 100644 index 0000000000..4b873b168c --- /dev/null +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt @@ -0,0 +1,212 @@ +package com.amaze.filemanager.filesystem.files + +import android.content.ContentResolver +import android.util.Log +import androidx.documentfile.provider.DocumentFile +import com.amaze.filemanager.application.AppConfig +import com.amaze.filemanager.file_operations.filesystem.OpenMode +import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFile +import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFilesystem +import com.amaze.filemanager.file_operations.filesystem.filetypes.ContextProvider +import com.amaze.filemanager.filesystem.FileProperties.getDeviceStorageRemainingSpace +import com.amaze.filemanager.filesystem.SafRootHolder.uriRoot +import com.amaze.filemanager.filesystem.SafRootHolder.volumeLabel +import com.amaze.filemanager.utils.OTGUtil.getDocumentFile +import java.io.FileNotFoundException +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream + +object DocumentFileAmazeFilesystem: AmazeFilesystem() { + @JvmStatic + val TAG = DocumentFileAmazeFilesystem::class.java.simpleName + + const val DOCUMENT_FILE_PREFIX = "content://com.android.externalstorage.documents" + + init { + AmazeFile.addFilesystem(this) + } + + override val prefix: String = DOCUMENT_FILE_PREFIX + + override fun normalize(path: String): String { + val documentFile = getDocumentFile(path, false) ?: return defaultParent + return documentFile.uri.path ?: defaultParent + } + + override fun resolve(parent: String, child: String): String { + val documentFile = getDocumentFile(parent, false) ?: return defaultParent + val childDocumentFile = documentFile.findFile(child) ?: return defaultParent + return childDocumentFile.uri.path ?: return defaultParent + } + + override fun resolve(f: AmazeFile): String { + TODO("Not yet implemented") + } + + override val defaultParent: String = DOCUMENT_FILE_PREFIX + getSeparator() + + override fun isAbsolute(f: AmazeFile): Boolean = true // All paths are absolute + + override fun canonicalize(path: String?): String { + TODO("Not yet implemented") + } + + override fun exists(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.exists() + } + + override fun isFile(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.isFile + } + + override fun isDirectory(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.isDirectory + } + + override fun isHidden(f: AmazeFile): Boolean { + throw NotImplementedError() + } + + override fun canExecute(f: AmazeFile, contextProvider: ContextProvider): Boolean { + throw NotImplementedError() + } + + override fun canWrite(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.canWrite() + } + + override fun canRead(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.canRead() + } + + override fun canAccess(f: AmazeFile, contextProvider: ContextProvider): Boolean { + return exists(f, contextProvider) + } + + override fun setExecutable(f: AmazeFile, enable: Boolean, owneronly: Boolean): Boolean { + return false //Can't set + } + + override fun setWritable(f: AmazeFile, enable: Boolean, owneronly: Boolean): Boolean { + return false //Can't set + } + + override fun setReadable(f: AmazeFile, enable: Boolean, owneronly: Boolean): Boolean { + return false //Can't set + } + + override fun getLastModifiedTime(f: AmazeFile): Long { + val documentFile = getDocumentFile(f.path, false) ?: return 0 + return documentFile.lastModified() + } + + override fun getLength(f: AmazeFile, contextProvider: ContextProvider): Long { + val documentFile = getDocumentFile(f.path, false) + ?: throw IOException("Could not create DocumentFile for length") + return documentFile.length() + } + + override fun createFileExclusively(pathname: String): Boolean { + TODO("Not yet implemented") + } + + override fun delete(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val documentFile = getDocumentFile(f.path, false) ?: return false + return documentFile.delete() + } + + override fun list(f: AmazeFile, contextProvider: ContextProvider): Array? { + val documentFile = getDocumentFile(f.path, false) ?: return null + return documentFile.listFiles().mapNotNull { it.uri.path }.toTypedArray() + } + + override fun getInputStream(f: AmazeFile, contextProvider: ContextProvider): InputStream? { + val context = contextProvider.getContext() ?: return null + val contentResolver: ContentResolver = context.contentResolver + val documentSourceFile = getDocumentFile(f.path, false) ?: return null + return try { + contentResolver.openInputStream(documentSourceFile.uri) + } catch (e: FileNotFoundException) { + Log.e(TAG, "Error getting input stream for DocumentFile", e) + null + } + } + + override fun getOutputStream(f: AmazeFile, contextProvider: ContextProvider): OutputStream? { + val context = contextProvider.getContext() ?: return null + val contentResolver: ContentResolver = context.contentResolver + val documentSourceFile = getDocumentFile(f.path, true) ?: return null + return try { + contentResolver.openOutputStream(documentSourceFile.uri) + } catch (e: FileNotFoundException) { + Log.e(TAG, "Error getting output stream for DocumentFile", e) + null + } + } + + override fun createDirectory(f: AmazeFile, contextProvider: ContextProvider): Boolean { + val context = contextProvider.getContext() ?: return false + if (!exists(f, contextProvider)) { + val uriRoot = uriRoot ?: return false + val parent = f.parent ?: return false + val parentDirectory = getDocumentFile( + parent, + uriRoot, + context, + OpenMode.DOCUMENT_FILE, + true + ) ?: return false + + if (parentDirectory.isDirectory) { + parentDirectory.createDirectory(f.name) ?: return false + return true + } + } + + return false + } + + override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { + TODO("Not yet implemented") + } + + override fun setLastModifiedTime(f: AmazeFile, time: Long): Boolean { + TODO("Not yet implemented") + } + + override fun setReadOnly(f: AmazeFile): Boolean { + return false //Can't set + } + + override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { + return getDocumentFile(defaultParent, false)?.length() ?: 0 + } + + override fun getFreeSpace(f: AmazeFile): Long { + return getUsableSpace(f) // Assume both are equal + } + + override fun getUsableSpace(f: AmazeFile): Long { + val volumeLabel = volumeLabel ?: return 0 + return getDeviceStorageRemainingSpace(volumeLabel) + } + + fun getDocumentFile(path: String, createRecursive: Boolean): DocumentFile? { + val uriRoot = uriRoot ?: return null + + return getDocumentFile( + path, + uriRoot, + AppConfig.getInstance(), + OpenMode.DOCUMENT_FILE, + createRecursive + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt b/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt index ef25f71629..ec58165444 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt +++ b/app/src/main/java/com/amaze/filemanager/filesystem/otg/OtgAmazeFilesystem.kt @@ -29,10 +29,10 @@ object OtgAmazeFilesystem : AmazeFilesystem() { return simpleUnixNormalize(path) } - override fun resolve(parent: String?, child: String?): String { - val prefix = parent!!.substring(0, prefixLength(parent)) + override fun resolve(parent: String, child: String): String { + val prefix = parent.substring(0, prefixLength(parent)) val simplePathParent = parent.substring(prefixLength(parent)) - val simplePathChild = child!!.substring(prefixLength(child)) + val simplePathChild = child.substring(prefixLength(child)) return prefix + basicUnixResolve(simplePathParent, simplePathChild) } @@ -113,7 +113,7 @@ object OtgAmazeFilesystem : AmazeFilesystem() { } @Throws(IOException::class) - override fun createFileExclusively(pathname: String?): Boolean { + override fun createFileExclusively(pathname: String): Boolean { return false } @@ -185,15 +185,6 @@ object OtgAmazeFilesystem : AmazeFilesystem() { return false } - override fun listRoots(): Array { - val roots = File.listRoots() - val amazeRoots = arrayOfNulls(roots.size) - for (i in roots.indices) { - amazeRoots[i] = AmazeFile(roots[i].path) - } - return arrayOf(AmazeFile(defaultParent)) - } - override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { val context = contextProvider.getContext() // TODO: Find total storage space of OTG when {@link DocumentFile} API adds support diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/ssh/SshAmazeFilesystem.java b/app/src/main/java/com/amaze/filemanager/filesystem/ssh/SshAmazeFilesystem.java index c1b39ecba6..2fdb9ddf7c 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/ssh/SshAmazeFilesystem.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/ssh/SshAmazeFilesystem.java @@ -58,7 +58,7 @@ public String normalize(@NonNull String path) { @NonNull @Override - public String resolve(String parent, String child) { + public String resolve(@NotNull String parent, @NotNull String child) { return PREFIX + new File(removePrefix(parent), child).getAbsolutePath(); } @@ -102,7 +102,7 @@ public boolean exists(AmazeFile f, @NonNull ContextProvider contextProvider) { final SFtpClientTemplate template = new SFtpClientTemplate(f.getPath()) { @Override public Boolean execute(@NonNull SFTPClient client) throws IOException { - return client.statExistence(f.getPath()) != null; + return client.stat(SshClientUtils.extractRemotePathFrom(f.getPath())) != null; } }; @@ -134,7 +134,7 @@ public boolean isDirectory(AmazeFile f, @NonNull ContextProvider contextProvider final SFtpClientTemplate template = new SFtpClientTemplate(f.getPath()) { @Override public Boolean execute(@NonNull SFTPClient client) throws IOException { - return client.lstat(f.getPath()).getType() == DIRECTORY; + return client.lstat(SshClientUtils.extractRemotePathFrom(f.getPath())).getType() == DIRECTORY; } }; @@ -228,7 +228,7 @@ public Long execute(@NonNull SFTPClient client) throws IOException { } @Override - public boolean createFileExclusively(String pathname) throws IOException { + public boolean createFileExclusively(@NotNull String pathname) { return false; } @@ -393,12 +393,6 @@ public boolean setReadOnly(AmazeFile f) { return false; } - @NotNull - @Override - public AmazeFile[] listRoots() { - return new AmazeFile[] { new AmazeFile(getDefaultParent()) }; - } - public long getTotalSpace(AmazeFile f, @NonNull ContextProvider contextProvider) { final Long returnValue = SshClientUtils.execute( diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt index ac954fb4e9..789cd803d9 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFile.kt @@ -20,7 +20,6 @@ package com.amaze.filemanager.file_operations.filesystem.filetypes import android.os.Parcel -import android.os.Parcelable import android.util.Log import kotlinx.parcelize.Parceler import java.io.File @@ -1115,13 +1114,6 @@ class AmazeFile : Comparable { } else fs.canExecute(this, contextProvider) } /* -- Filesystem interface -- */ // Android-changed: Replaced generic platform info with Android specific one. - /** - * Returns the file system roots. On Android and other Unix systems, there is a single root, - * `/`. - */ - fun listRoots(): Array { - return fs.listRoots() - } /* -- Disk usage -- */ /** * Returns the size of the partition [named](#partName) by this abstract pathname. diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt index 5245e10dcb..da7ace64a3 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/AmazeFilesystem.kt @@ -55,7 +55,7 @@ abstract class AmazeFilesystem { * Resolve the child pathname string against the parent. Both strings must be in normal form, and * the result will be in normal form. */ - abstract fun resolve(parent: String?, child: String?): String + abstract fun resolve(parent: String, child: String): String /** * Return the parent pathname string to be used when the parent-directory argument in one of the @@ -168,7 +168,7 @@ abstract class AmazeFilesystem { * Throw an IOException if an I/O error occurs. */ @Throws(IOException::class) - abstract fun createFileExclusively(pathname: String?): Boolean + abstract fun createFileExclusively(pathname: String): Boolean /** * Delete the file or directory denoted by the given abstract pathname, returning `true @@ -214,8 +214,6 @@ abstract class AmazeFilesystem { return path.substring(prefixLength(path)) } /* -- Filesystem interface -- */ - /** List the available filesystem roots. */ - abstract fun listRoots(): Array abstract fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long abstract fun getFreeSpace(f: AmazeFile): Long abstract fun getUsableSpace(f: AmazeFile): Long diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/cloud/CloudAmazeFilesystem.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/cloud/CloudAmazeFilesystem.kt index f7dfe5a9cf..1acf26a90c 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/cloud/CloudAmazeFilesystem.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/cloud/CloudAmazeFilesystem.kt @@ -49,7 +49,7 @@ abstract class CloudAmazeFilesystem : AmazeFilesystem() { return canonical.substring(0, canonical.length - 1) } - override fun resolve(parent: String?, child: String?): String { + override fun resolve(parent: String, child: String): String { return prefix + File(removePrefix(parent!!), child) } @@ -143,7 +143,7 @@ abstract class CloudAmazeFilesystem : AmazeFilesystem() { } @Throws(IOException::class) - override fun createFileExclusively(pathname: String?): Boolean { + override fun createFileExclusively(pathname: String): Boolean { return false } @@ -203,10 +203,6 @@ abstract class CloudAmazeFilesystem : AmazeFilesystem() { return false // This doesn't seem possible } - override fun listRoots(): Array { - return arrayOf(AmazeFile("$prefix/")) - } - override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { val account = account.account Objects.requireNonNull(account) diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/file/FileAmazeFilesystem.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/file/FileAmazeFilesystem.kt index 6f0a48279d..33d859eabf 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/file/FileAmazeFilesystem.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/file/FileAmazeFilesystem.kt @@ -63,7 +63,7 @@ object FileAmazeFilesystem: AmazeFilesystem() { return if (path[0] == '/') 1 else 0 } - override fun resolve(parent: String?, child: String?): String { + override fun resolve(parent: String, child: String): String { return File(parent, child).path } @@ -137,7 +137,7 @@ object FileAmazeFilesystem: AmazeFilesystem() { } @Throws(IOException::class) - override fun createFileExclusively(pathname: String?): Boolean { + override fun createFileExclusively(pathname: String): Boolean { return File(pathname).createNewFile() } @@ -281,13 +281,6 @@ object FileAmazeFilesystem: AmazeFilesystem() { return File(f.path).setReadOnly() } - override fun listRoots(): Array { - val roots = File.listRoots() - return Array(roots.size) { i: Int -> - AmazeFile(roots[i].path) - } - } - override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { return File(f.path).totalSpace } diff --git a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/smb/SmbAmazeFilesystem.kt b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/smb/SmbAmazeFilesystem.kt index 004c7a500b..94497e5da6 100644 --- a/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/smb/SmbAmazeFilesystem.kt +++ b/file_operations/src/main/java/com/amaze/filemanager/file_operations/filesystem/filetypes/smb/SmbAmazeFilesystem.kt @@ -147,7 +147,7 @@ object SmbAmazeFilesystem: AmazeFilesystem() { return matcher.end() } - override fun resolve(parent: String?, child: String?): String { + override fun resolve(parent: String, child: String): String { val prefix = parent!!.substring(0, prefixLength(parent)) val simplePathParent = parent.substring(prefixLength(parent)) val simplePathChild = child!!.substring(prefixLength(child)) @@ -297,7 +297,7 @@ object SmbAmazeFilesystem: AmazeFilesystem() { } @Throws(IOException::class) - override fun createFileExclusively(pathname: String?): Boolean { + override fun createFileExclusively(pathname: String): Boolean { create(pathname).mkdirs() return true } @@ -401,10 +401,6 @@ object SmbAmazeFilesystem: AmazeFilesystem() { } } - override fun listRoots(): Array { - throw NotImplementedError() - } - override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { // TODO: Find total storage space of SMB when JCIFS adds support throw NotImplementedError()