aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2015-08-21 10:34:33 -0700
committerStephen Bird <sbird@cyngn.com>2015-08-21 11:42:00 -0700
commit8f6788469828c169c97529252bbbce12e5dbfed1 (patch)
tree57ed2ab9d495e19e4a781cd73d743865f992c1dc
parent119a87057327ca72428e0a8b326a880d0f558b2d (diff)
downloadandroid_packages_apps_CMFileManager-8f6788469828c169c97529252bbbce12e5dbfed1.tar.gz
android_packages_apps_CMFileManager-8f6788469828c169c97529252bbbce12e5dbfed1.tar.bz2
android_packages_apps_CMFileManager-8f6788469828c169c97529252bbbce12e5dbfed1.zip
Fix MediaScan issue w/ Deleting
Mediascan wasn't working with deletion of items. We need to grab the items to delete before actually deleting them from the file system so that we know which items we should have deleted. Change-Id: Ia7b6d5c0612b8053d6b3f442dc9cc9312b02e47b Ticket: QRDL-982 (cherry picked from commit d5372f98c001a58cfdf332af0875a424ca0087da)
-rw-r--r--src/com/cyanogenmod/filemanager/util/CommandHelper.java59
1 files changed, 53 insertions, 6 deletions
diff --git a/src/com/cyanogenmod/filemanager/util/CommandHelper.java b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
index 81a397c2..625499e7 100644
--- a/src/com/cyanogenmod/filemanager/util/CommandHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;
+import android.util.Log;
import com.cyanogenmod.filemanager.commands.AsyncResultListener;
import com.cyanogenmod.filemanager.commands.ChangeOwnerExecutable;
import com.cyanogenmod.filemanager.commands.ChangePermissionsExecutable;
@@ -100,6 +101,8 @@ import java.util.Stack;
*/
public final class CommandHelper {
+ private static final String TAG = "CommandHelper";
+
/**
* A wrapper class for asynchronous operations that need restore the filesystem
* after the operation.
@@ -358,6 +361,47 @@ public final class CommandHelper {
return executable.getResult().booleanValue();
}
+ private static String[] collectScanPaths(final Context context, String path) {
+ ArrayList<String> paths = new ArrayList<>();
+ Stack<FileSystemObject> pathsToScan = new Stack<>();
+ try {
+ FileSystemObject fso = getFileInfo(context, path, null);
+ if (fso == null) {
+ return new String[0];
+ }
+ pathsToScan.push(fso);
+ while (!pathsToScan.isEmpty()) {
+ fso = pathsToScan.pop();
+ paths.add(MediaHelper.normalizeMediaPath(fso.getFullPath()));
+ if (fso instanceof Directory) {
+ List<FileSystemObject> files =
+ CommandHelper.listFiles(context, fso.getFullPath(), null);
+ if (files == null) {
+ continue;
+ }
+ for (FileSystemObject file : files) {
+ if (file instanceof ParentDirectory) {
+ continue;
+ }
+ pathsToScan.push(file);
+ }
+ }
+ }
+ return paths.toArray(new String[paths.size()]);
+ } catch (IOException
+ | ConsoleAllocException
+ | NoSuchFileOrDirectory
+ | InsufficientPermissionsException
+ | CommandNotFoundException
+ | OperationTimeoutException
+ | ExecutionException
+ | InvalidCommandDefinitionException e) {
+ // Just stop scanning
+ Log.e(TAG, "Recursive Delete Failed with: ", e);
+ return new String[0];
+ }
+ }
+
/**
* Method that deletes a directory.
*
@@ -385,14 +429,16 @@ public final class CommandHelper {
CommandNotFoundException, OperationTimeoutException,
ExecutionException, InvalidCommandDefinitionException, ReadOnlyFilesystemException,
CancelledOperationException {
+
+ String[] pathsToScan = collectScanPaths(context, directory);
+
Console c = ensureConsoleForFile(context, console, directory);
DeleteDirExecutable executable =
c.getExecutableFactory().newCreator().createDeleteDirExecutable(directory);
writableExecute(context, executable, c);
- // update media scan
- MediaScannerConnection.scanFile(context, new String[]{
- MediaHelper.normalizeMediaPath(directory)}, null, null);
+ // Remove from mediascanner
+ MediaScannerConnection.scanFile(context, pathsToScan, null, null);
return executable.getResult().booleanValue();
}
@@ -424,15 +470,16 @@ public final class CommandHelper {
CommandNotFoundException, OperationTimeoutException,
ExecutionException, InvalidCommandDefinitionException, ReadOnlyFilesystemException,
CancelledOperationException {
+
+ String[] pathsToScan = collectScanPaths(context, file);
+
Console c = ensureConsoleForFile(context, console, file);
DeleteFileExecutable executable =
c.getExecutableFactory().newCreator().createDeleteFileExecutable(file);
writableExecute(context, executable, c);
// Remove from mediascanner
- MediaScannerConnection.scanFile(context, new String[]{
- MediaHelper.normalizeMediaPath(file)
- }, null, null);
+ MediaScannerConnection.scanFile(context, pathsToScan, null, null);
return executable.getResult().booleanValue();
}