Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdb2c84b authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

refactor end of 'ObserverService.handleRemoteRemainingSyncedFileState()'

parent cf0ac960
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -498,26 +498,20 @@ public class ObserverService extends Service implements OnRemoteOperationListene
            final File file = new File( syncedFileStates.get(i).getLocalPath() );

            //Try to remove local file
            boolean fileExists = file.exists();
            if (fileExists) {
                Log.d(TAG, file.getName()+" exists *1");
                //delete file
            if (file.exists()) {
                int rowAffected = getContentResolver().delete(MediaStore.Files.getContentUri("external"),
                        MediaStore.Files.FileColumns.DATA + "=?",
                        new String[]{CommonUtils.getLocalPath(file)});
                Log.d(TAG, "deleted rows by mediastore : " + rowAffected);
                //sometimes (it seems to be relative to file's type) mediastore don't remove local file from storage
                fileExists = !file.delete();

                if (!file.delete()) { //May throw SecurityException or IOException
                    Log.w(TAG, "local file (" + file.getName() + ") removal failed.");
                    continue;
                }
            }

            //if it succeed, remove syncedFileState in DB
            if (!fileExists) {
                //It means that file has been correctly deleted from device. So update DB.
            if (DbHelper.manageSyncedFileStateDB(syncedFileState, "DELETE", this) <= 0) {
                    Log.e(TAG, "SyncedFileState row hasn't been deleted from DB");
                }
            } else {
                Log.w(TAG, "local file:" + file.getName() + " still exist and can't be remove");
                Log.e(TAG, "Failed to remove " + file.getName() + " from DB");
            }
        }
    }