aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2015-08-21 10:34:33 -0700
committerMartin Brabham <mbrabham@cyngn.com>2015-08-21 11:40:38 -0700
commitd5372f98c001a58cfdf332af0875a424ca0087da (patch)
tree00d13f3cbc83a84ba50fb271b5572fa76345b563
parent530d6f62fb11271cdc0fef6ac3bee10fa550c9e0 (diff)
downloadandroid_packages_apps_CMFileManager-d5372f98c001a58cfdf332af0875a424ca0087da.tar.gz
android_packages_apps_CMFileManager-d5372f98c001a58cfdf332af0875a424ca0087da.tar.bz2
android_packages_apps_CMFileManager-d5372f98c001a58cfdf332af0875a424ca0087da.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
-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 eeac5309..85808daf 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();
}