|
47 | 47 | import com.nextcloud.model.ShareeEntry; |
48 | 48 | import com.nextcloud.utils.date.DateFormatPattern; |
49 | 49 | import com.nextcloud.utils.extensions.DateExtensionsKt; |
| 50 | +import com.nextcloud.utils.extensions.FileExtensionsKt; |
| 51 | +import com.nextcloud.utils.extensions.StringExtensionsKt; |
50 | 52 | import com.owncloud.android.MainApp; |
51 | 53 | import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; |
52 | 54 | import com.owncloud.android.lib.common.network.WebdavEntry; |
@@ -912,25 +914,31 @@ public boolean removeFile(OCFile ocFile, boolean removeDBData, boolean removeLoc |
912 | 914 | } |
913 | 915 |
|
914 | 916 | private boolean removeLocalCopyIfNeeded(OCFile ocFile, boolean removeLocalCopy, boolean removeDBData) { |
915 | | - String localPath = ocFile.getStoragePath(); |
916 | | - |
917 | 917 | if (!removeLocalCopy) { |
918 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false"); |
| 918 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: removeLocalCopy=false"); |
919 | 919 | return true; |
920 | 920 | } |
921 | 921 |
|
922 | | - if (!ocFile.isDown()) { |
923 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: file not downloaded -> skip"); |
| 922 | + String localPath = ocFile.getStoragePath(); |
| 923 | + final var file = FileExtensionsKt.toFile(localPath); |
| 924 | + if (file == null) { |
| 925 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: file exists -> skip"); |
924 | 926 | return true; |
925 | 927 | } |
926 | 928 |
|
927 | | - if (localPath == null) { |
928 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: localPath is null -> skip"); |
| 929 | + if (ocFile.isFolder()) { |
| 930 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: file is folder -> skip"); |
929 | 931 | return true; |
930 | 932 | } |
931 | 933 |
|
932 | | - Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath); |
| 934 | + String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile); |
| 935 | + if (!localPath.equalsIgnoreCase(expectedPath)) { |
| 936 | + Log_OC.w(TAG, "removeLocalCopyIfNeeded: Path mismatch! Expected " + expectedPath |
| 937 | + + " but found " + localPath + ". Skipping deletion to prevent data loss."); |
| 938 | + return true; |
| 939 | + } |
933 | 940 |
|
| 941 | + Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath); |
934 | 942 | boolean success = new File(localPath).delete(); |
935 | 943 | Log_OC.d(TAG, "removeLocalCopyIfNeeded: file deletion result=" + success); |
936 | 944 |
|
|
0 commit comments