diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/Operations.java b/app/src/main/java/com/amaze/filemanager/filesystem/Operations.java index 6b943d4cf8..507ec2513e 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/Operations.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/Operations.java @@ -68,7 +68,7 @@ public class Operations { - private static Executor executor = AsyncTask.THREAD_POOL_EXECUTOR; + private static final Executor executor = AsyncTask.THREAD_POOL_EXECUTOR; private static final String TAG = Operations.class.getSimpleName(); @@ -120,7 +120,7 @@ public static void mkdir( @NonNull final ErrorCallBack errorCallBack) { new AsyncTask() { - private Function safCreateDirectory = + private final Function safCreateDirectory = input -> { if (input != null && input.isDirectory()) { boolean result = false; @@ -251,9 +251,9 @@ public static void mkfile( new AsyncTask() { - private DataUtils dataUtils = DataUtils.getInstance(); + private final DataUtils dataUtils = DataUtils.getInstance(); - private Function safCreateFile = + private final Function safCreateFile = input -> { if (input != null && input.isDirectory()) { boolean result = false; @@ -425,18 +425,6 @@ public static void rename( private final DataUtils dataUtils = DataUtils.getInstance(); - private Function safRenameFile = - input -> { - boolean result = false; - try { - result = input.renameTo(newFile.getName(context)); - } catch (Exception e) { - Log.w(getClass().getSimpleName(), "Failed to rename", e); - } - errorCallBack.done(newFile, result); - return null; - }; - @Override protected Void doInBackground(Void... params) { // check whether file names for new file are valid or recursion occurs. @@ -450,17 +438,17 @@ protected Void doInBackground(Void... params) { errorCallBack.exists(newFile); return null; } + AmazeFile amazeFile = new AmazeFile(oldFile.getPath()); + // FIXME: smbFile1 should be created from SmbUtil too so it can be mocked + AmazeFile amazeFile1 = new AmazeFile(newFile.getPath()); if (oldFile.isSmb()) { - AmazeFile smbFile = new AmazeFile(oldFile.getPath()); - // FIXME: smbFile1 should be created from SmbUtil too so it can be mocked - AmazeFile smbFile1 = new AmazeFile(newFile.getPath()); if (newFile.exists()) { errorCallBack.exists(newFile); return null; } - smbFile.renameTo(smbFile1, () -> context); - if (!smbFile.exists(() -> context) && smbFile1.exists(() -> context)) { + amazeFile.renameTo(amazeFile1, () -> context); + if (!amazeFile.exists(() -> context) && amazeFile1.exists(() -> context)) { errorCallBack.done(newFile, true); return null; } else { @@ -474,104 +462,46 @@ protected Void doInBackground(Void... params) { Log.e(TAG, "Error creating HybridFileParcelable", exceptionThrownDuringBuildParcelable); } } + return null; } else if (oldFile.isSftp()) { - SshClientUtils.execute( - new SFtpClientTemplate(oldFile.getPath()) { - @Override - public Void execute(@NonNull SFTPClient client) { - try { - client.rename( - SshClientUtils.extractRemotePathFrom(oldFile.getPath()), - SshClientUtils.extractRemotePathFrom(newFile.getPath())); - errorCallBack.done(newFile, true); - } catch (IOException e) { - String errmsg = - context.getString( - R.string.cannot_rename_file, - HybridFile.parseAndFormatUriForDisplay(oldFile.getPath()), - e.getMessage()); - Log.e(TAG, errmsg); - ArrayList failedOps = new ArrayList<>(); - // Nobody care the size or actual permission here. Put a simple "r" and zero - // here - failedOps.add( - new HybridFileParcelable( + boolean result = amazeFile.renameTo(amazeFile1, () -> context); + + if(!result) { + ArrayList failedOps = new ArrayList<>(); + // Nobody care the size or actual permission here. Put a simple "r" and zero + // here + failedOps.add( + new HybridFileParcelable( oldFile.getPath(), "r", oldFile.lastModified(), 0, oldFile.isDirectory(context))); - context.sendBroadcast( - new Intent(TAG_INTENT_FILTER_GENERAL) + context.sendBroadcast( + new Intent(TAG_INTENT_FILTER_GENERAL) .putParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS, failedOps)); - errorCallBack.done(newFile, false); - } - return null; - } - }); - } else if (oldFile.isDropBoxFile()) { - CloudStorage cloudStorageDropbox = DropboxAccount.INSTANCE.getAccount(); - try { - cloudStorageDropbox.move( - CloudUtil.stripPath(OpenMode.DROPBOX, oldFile.getPath()), - CloudUtil.stripPath(OpenMode.DROPBOX, newFile.getPath())); - errorCallBack.done(newFile, true); - } catch (Exception e) { - e.printStackTrace(); - errorCallBack.done(newFile, false); - } - } else if (oldFile.isBoxFile()) { - CloudStorage cloudStorageBox = BoxAccount.INSTANCE.getAccount(); - try { - cloudStorageBox.move( - CloudUtil.stripPath(OpenMode.BOX, oldFile.getPath()), - CloudUtil.stripPath(OpenMode.BOX, newFile.getPath())); - errorCallBack.done(newFile, true); - } catch (Exception e) { - e.printStackTrace(); - errorCallBack.done(newFile, false); - } - } else if (oldFile.isOneDriveFile()) { - CloudStorage cloudStorageOneDrive = OnedriveAccount.INSTANCE.getAccount(); - try { - cloudStorageOneDrive.move( - CloudUtil.stripPath(OpenMode.ONEDRIVE, oldFile.getPath()), - CloudUtil.stripPath(OpenMode.ONEDRIVE, newFile.getPath())); - errorCallBack.done(newFile, true); - } catch (Exception e) { - e.printStackTrace(); - errorCallBack.done(newFile, false); - } - } else if (oldFile.isGoogleDriveFile()) { - CloudStorage cloudStorageGdrive = GoogledriveAccount.INSTANCE.getAccount(); - try { - cloudStorageGdrive.move( - CloudUtil.stripPath(OpenMode.GDRIVE, oldFile.getPath()), - CloudUtil.stripPath(OpenMode.GDRIVE, newFile.getPath())); - errorCallBack.done(newFile, true); - } catch (Exception e) { - e.printStackTrace(); - errorCallBack.done(newFile, false); } + + errorCallBack.done(newFile, result); + } else if (oldFile.isDropBoxFile() || oldFile.isBoxFile() || oldFile.isOneDriveFile() + || oldFile.isGoogleDriveFile()) { + boolean result = amazeFile.renameTo(amazeFile1, () -> context); + errorCallBack.done(newFile, result); } else if (oldFile.isOtgFile()) { if (checkOtgNewFileExists(newFile, context)) { errorCallBack.exists(newFile); return null; } - safRenameFile.apply(OTGUtil.getDocumentFile(oldFile.getPath(), context, false)); + boolean result = amazeFile.renameTo(amazeFile1, () -> context); + errorCallBack.done(newFile, result); return null; } else if (oldFile.isDocumentFile()) { if (checkDocumentFileNewFileExists(newFile, context)) { errorCallBack.exists(newFile); return null; } - safRenameFile.apply( - OTGUtil.getDocumentFile( - oldFile.getPath(), - SafRootHolder.getUriRoot(), - context, - OpenMode.DOCUMENT_FILE, - false)); + boolean result = amazeFile.renameTo(amazeFile1, () -> context); + errorCallBack.done(newFile, result); return null; } else { File file = new File(oldFile.getPath()); 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 index 4b873b168c..e06dec1fe7 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/DocumentFileAmazeFilesystem.kt @@ -11,6 +11,7 @@ import com.amaze.filemanager.file_operations.filesystem.filetypes.ContextProvide 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.filesystem.otg.OtgAmazeFilesystem import com.amaze.filemanager.utils.OTGUtil.getDocumentFile import java.io.FileNotFoundException import java.io.IOException @@ -172,12 +173,28 @@ object DocumentFileAmazeFilesystem: AmazeFilesystem() { return false } - override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { - TODO("Not yet implemented") + override fun rename(file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean { + val context = contextProvider.getContext() ?: return false + val uriRoot = uriRoot ?: return false + + val documentFile = getDocumentFile( + file1.path, + uriRoot, + context, + OpenMode.DOCUMENT_FILE, + false + ) ?: return false + + return try { + documentFile.renameTo(file2.name) + } catch (e: Exception) { + Log.e(TAG, "Error renaming DocumentFile file", e) + false + } } override fun setLastModifiedTime(f: AmazeFile, time: Long): Boolean { - TODO("Not yet implemented") + return false //Can't set } override fun setReadOnly(f: AmazeFile): Boolean { 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 ec58165444..8373e1d112 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 @@ -1,12 +1,12 @@ package com.amaze.filemanager.filesystem.otg import android.util.Log -import com.amaze.filemanager.utils.OTGUtil.getDocumentFile -import com.amaze.filemanager.file_operations.filesystem.filetypes.AmazeFilesystem 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.utils.OTGUtil +import com.amaze.filemanager.utils.OTGUtil.getDocumentFile import java.io.* -import java.util.ArrayList object OtgAmazeFilesystem : AmazeFilesystem() { @JvmStatic @@ -162,19 +162,23 @@ object OtgAmazeFilesystem : AmazeFilesystem() { } val context = contextProvider.getContext() ?: return false val parent = f.parent ?: return false - val parentDirectory = getDocumentFile(parent, context, true) - if (parentDirectory!!.isDirectory) { + val parentDirectory = getDocumentFile(parent, context, true) ?: return false + if (parentDirectory.isDirectory) { parentDirectory.createDirectory(f.name) return true } return false } - override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { - val context = contextProvider.getContext() - val contentResolver = context!!.contentResolver - val documentSourceFile = getDocumentFile(f1.path, context, true) - return documentSourceFile!!.renameTo(f2.path) + override fun rename(file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean { + val context = contextProvider.getContext() ?: return false + val documentSourceFile = getDocumentFile(file1.path, context, false) ?: return false + return try { + documentSourceFile.renameTo(file2.name) + } catch (e: UnsupportedOperationException) { + Log.e(TAG, "Error renaming OTG file", e) + false + } } override fun setLastModifiedTime(f: AmazeFile, time: Long): Boolean { 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 2fdb9ddf7c..73eeba6b65 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 @@ -1,16 +1,23 @@ package com.amaze.filemanager.filesystem.ssh; +import static com.amaze.filemanager.ui.activities.MainActivity.TAG_INTENT_FILTER_FAILED_OPS; +import static com.amaze.filemanager.ui.activities.MainActivity.TAG_INTENT_FILTER_GENERAL; import static net.schmizz.sshj.sftp.FileMode.Type.DIRECTORY; import static net.schmizz.sshj.sftp.FileMode.Type.REGULAR; +import android.content.Context; +import android.content.Intent; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.amaze.filemanager.R; 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.HybridFile; +import com.amaze.filemanager.filesystem.HybridFileParcelable; import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.common.Buffer; @@ -358,17 +365,27 @@ public Void execute(@NonNull SFTPClient client) { } @Override - public boolean rename(AmazeFile f1, AmazeFile f2, @NonNull ContextProvider contextProvider) { + public boolean rename(AmazeFile file1, AmazeFile file2, @NonNull ContextProvider contextProvider) { + @Nullable final Context context = contextProvider.getContext(); + + if(context == null) { + Log.e(TAG, "Error getting context for renaming ssh file"); + return false; + } + Boolean retval = - SshClientUtils.execute( - new SFtpClientTemplate(f1.getPath()) { + SshClientUtils.execute( + new SFtpClientTemplate(file1.getPath()) { @Override - public Boolean execute(@NonNull SFTPClient client) throws IOException { + public Boolean execute(@NonNull SFTPClient client) { try { - client.rename(f1.getPath(), f2.getPath()); + client.rename( + SshClientUtils.extractRemotePathFrom(file1.getPath()), + SshClientUtils.extractRemotePathFrom(file2.getPath()) + ); return true; } catch (IOException e) { - Log.e(TAG, "Error renaming over SFTP", e); + Log.e(TAG, "Error renaming ssh file", e); return false; } } diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index b79b5223bd..5c80ec0e3a 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -665,7 +665,6 @@ الغاء اتاحة التحقق من توقيع IPC (بالنسبة لوحدات خدمة SMBv1 القديمة-UNSAFE !) لا يمكن حذف الملف لا يمكن حذف الملف-%s - لا يمكن اعادة تسمية الملف %s-%s لا يمكن قراءة الدليل %s-%s مرة واحدة فقط دائما diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 813a82be10..fcaa0d7b09 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -630,7 +630,6 @@ andernfalls wird nach Treffern gesucht. IPC Signaturprüfung deaktivieren (Für veraltete SMBv1 Server - UNSICHER!) Datei kann nicht gelöscht werden Datei %s kann nicht gelöscht werden - Datei %s - %s kann nicht umbenannt werden Verzeichnis %s - %s kann nicht gelesen werden Nur einmal Immer diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 180ddf54cc..a7079c28d8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -670,7 +670,6 @@ Desactive la verificación de firma de IPC (para servidores SMBv1 heredados - ¡INSEGURO!) No se puede eliminar el archivo No se puede eliminar el archivo - %s - No se puede renombrar el archivo %s - %s No se puede leer el directorio %s - %s Sólo una vez Siempre diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2c9ebb55e9..694a523ee7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -646,7 +646,6 @@ Désactiver la vérification de la signature IPC (Pour les anciens serveurs SMBv1 - RISQUÉ!) Impossible de supprimer le fichier Impossible de supprimer le fichier - %s - Impossible de renommer le fichier %s - %s Impossible de lire le répertoire %s - %s Juste une fois Toujours diff --git a/app/src/main/res/values-he/strings.xml b/app/src/main/res/values-he/strings.xml index 7ecd40896c..af71034da8 100644 --- a/app/src/main/res/values-he/strings.xml +++ b/app/src/main/res/values-he/strings.xml @@ -679,7 +679,6 @@ השבתת בדיקת חתימת IPC (לשרתי SMBv1 מיושנים - מסוכן!) לא ניתן למחוק קובץ לא ניתן למחוק קובץ - %s - לא ניתן לשנות את שם הקובץ %s - %s לא ניתן לקרוא את התיקייה %s - %s רק פעם אחת תמיד diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 275519b758..ad6bd072cb 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -683,7 +683,6 @@ IPC-aláírás ellenőrzés letiltása (Örökölt SMBv1-kiszolgálókhoz - UNSAFE!) Nem lehet törölni a fájlt Nem lehet törölni a fájlt - %s - Nem lehet átnevezni a fájlt %s - %s Nem lehet olvasni a könyvtárat %s - %s Csak egyszer Mindig diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 16ab82c044..f5e5e4c0b1 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -678,7 +678,6 @@ Nonaktifkan pemeriksaaan tanda tangan IPC (Untuk server SMBv1 lama - TIDAK AMAN!) Tidak bisa menghapus berkas Tidak bisa menghapus berkas - %s - Tidak bisa mengubah nama berkas %s - %s Tidak bisa membaca direktori %s - %s Hanya Sekali Selalu diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 7bcfc05fe2..2a096fe936 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -660,7 +660,6 @@ Wi-Fiに接続する必要があります。\n\n クラッシュ報告がクリップボードにコピーしました ファイルを削除できません ファイルを削除できません - %s - ファイル %s 名前を変更できません - %s 一回だけ 常に 別にAppを選ぶ diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 6f6b7c36f2..61bb363f83 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -657,7 +657,6 @@ Desative a verificação de assinatura IPC (Para servidores SMBv1 legados - INSEGURO!) Não foi possível deletar o arquivo Não foi possível deletar o arquivo%s - Não foi possível renomear o arquivo%s%s Não foi possível acessar o diretório%s%s Apenas uma vez Sempre diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 9ec75e2725..c4503dfbc8 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -645,7 +645,6 @@ Вимкнути перевірку підписання IPC (для застарілих серверів SMBv1 - НЕБЕЗПЕЧНО!) Не вдається видалити файл Не вдається видалити файл - %s - Не вдається перейменувати файл %s - %s Не вжається прочитати каталог %s - %s Лише цього разу Завжди diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index bbbd4449ea..e244fa7a02 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -679,7 +679,6 @@ Tắt kiểm tra ký IPC (Đối với máy chủ SMBv1 cũ - KHÔNG AN TOÀN!) Không thể xóa tập tin Không thể xóa tập tin - %s - Không thể đổi tên tập tin %s - %s Không thể đọc thư mục %s - %s Chỉ một lần Luôn luôn diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4a80320005..78735bbd45 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -652,7 +652,6 @@ 详情: 无法删除文件 无法删除文件 - %s - 无法重命名文件%s-%s 无法读取文件夹%s-%s 仅本次 总是 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 1681fcd08b..a2fbcedef9 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -621,7 +621,6 @@ 關閉 IPC簽名檢查(對應舊式嘅 SMBv1伺服器 - 唔安全㗎!) 個檔案刪除唔到 個檔案刪除唔到 - %s - 檔案 %s 改唔到名 - %s 讀唔到檔案夾 %s - %s 只限呢次 以後都係 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index bd657a182a..3cb8569427 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -665,7 +665,6 @@ 關閉 IPC數位簽名檢查(適用於舊式 SMBv1伺服器—不安全!) 無法刪除檔案 無法刪除檔案 - %s - 無法重新命名檔案 %s - %s 無法讀取檔案夾 %s - %s 只此一次 總是 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 423d70b789..8fd86920ec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -688,7 +688,6 @@ Disable IPC signing check (For legacy SMBv1 servers - UNSAFE!) Cannot delete file Cannot delete file - %s - Cannot rename file %s - %s Cannot read directory %s - %s Just Once Always 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 da7ace64a3..0507c2ea43 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 @@ -197,7 +197,7 @@ abstract class AmazeFilesystem { * pathname, returning `true` if and only if the operation succeeds. */ abstract fun rename( - f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean + file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean /** * Set the last-modified time of the file or directory denoted by the given abstract pathname, 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 1acf26a90c..272d2d0cfd 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 @@ -176,26 +176,23 @@ abstract class CloudAmazeFilesystem : AmazeFilesystem() { } override fun createDirectory(f: AmazeFile, contextProvider: ContextProvider): Boolean { - val account = account.account - Objects.requireNonNull(account) + val account = account.account ?: return false val noPrefixPath = removePrefix(f.path) - account!!.createFolder(noPrefixPath) + account.createFolder(noPrefixPath) return true // This seems to never fail } - override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { - val account = account.account - Objects.requireNonNull(account) - account!!.move(removePrefix(f1.path), removePrefix(f2.path)) + override fun rename(file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean { + val account = account.account ?: return false + account.move(removePrefix(file1.path), removePrefix(file2.path)) return true // This seems to never fail } override fun setLastModifiedTime(f: AmazeFile, time: Long): Boolean { - val account = account.account - Objects.requireNonNull(account) + val account = account.account ?: return false val noPrefixPath = removePrefix(f.path) // TODO check that this actually returns seconds since epoch - account!!.getMetadata(noPrefixPath).contentModifiedAt = time + account.getMetadata(noPrefixPath).contentModifiedAt = time return true // This seems to never fail } @@ -204,23 +201,20 @@ abstract class CloudAmazeFilesystem : AmazeFilesystem() { } override fun getTotalSpace(f: AmazeFile, contextProvider: ContextProvider): Long { - val account = account.account - Objects.requireNonNull(account) - val spaceAllocation = account!!.allocation + val account = account.account ?: return 0 + val spaceAllocation = account.allocation return spaceAllocation.total } override fun getFreeSpace(f: AmazeFile): Long { - val account = account.account - Objects.requireNonNull(account) - val spaceAllocation = account!!.allocation + val account = account.account ?: return 0 + val spaceAllocation = account.allocation return spaceAllocation.total - spaceAllocation.used } override fun getUsableSpace(f: AmazeFile): Long { - val account = account.account - Objects.requireNonNull(account) - val spaceAllocation = account!!.allocation + val account = account.account ?: return 0 + val spaceAllocation = account.allocation return spaceAllocation.total - spaceAllocation.used } 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 33d859eabf..5aa79bbc65 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 @@ -269,8 +269,8 @@ object FileAmazeFilesystem: AmazeFilesystem() { } else false } - override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { - return File(f1.path).renameTo(File(f2.path)) + override fun rename(file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean { + return File(file1.path).renameTo(File(file2.path)) } override fun setLastModifiedTime(f: AmazeFile, time: Long): Boolean { 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 94497e5da6..b306406675 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 @@ -362,9 +362,9 @@ object SmbAmazeFilesystem: AmazeFilesystem() { } } - override fun rename(f1: AmazeFile, f2: AmazeFile, contextProvider: ContextProvider): Boolean { + override fun rename(file1: AmazeFile, file2: AmazeFile, contextProvider: ContextProvider): Boolean { return try { - create(f1!!.path).renameTo(create(f2!!.path)) + create(file1.path).renameTo(create(file2.path)) true } catch (e: SmbException) { Log.e(TAG, "Error getting SMB files for a rename", e)