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

Commit ac455993 authored by Tony Huang's avatar Tony Huang Committed by Jeff Sharkey
Browse files

Fix ExternalStorageProvider always throw exception when rename

ExternalStorageProvider always throw exception when renameDocument
because it will check file exist when getFileForDocId. However,
beforeVisibleFile is not exist after rename, it will throw
exception. Fix it by put getting beforeVisibleFile before rename.

Test: manual test rename in DocumentsUI
Test: atest RenameActualProviderUiTest
Fix: 113302685
Fix: 115304092
Change-Id: I45d60d2f940e3dbc2b121f7cd28acc3c2d085ec4
Merged-In: I45d60d2f940e3dbc2b121f7cd28acc3c2d085ec4
parent e238a19a
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -236,6 +236,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        displayName = FileUtils.buildValidFatFilename(displayName);
        displayName = FileUtils.buildValidFatFilename(displayName);


        final File before = getFileForDocId(docId);
        final File before = getFileForDocId(docId);
        final File beforeVisibleFile = getFileForDocId(docId, true);
        final File after = FileUtils.buildUniqueFile(before.getParentFile(), displayName);
        final File after = FileUtils.buildUniqueFile(before.getParentFile(), displayName);
        if (!before.renameTo(after)) {
        if (!before.renameTo(after)) {
            throw new IllegalStateException("Failed to rename to " + after);
            throw new IllegalStateException("Failed to rename to " + after);
@@ -245,7 +246,6 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        onDocIdChanged(docId);
        onDocIdChanged(docId);
        onDocIdChanged(afterDocId);
        onDocIdChanged(afterDocId);


        final File beforeVisibleFile = getFileForDocId(docId, true);
        final File afterVisibleFile = getFileForDocId(afterDocId, true);
        final File afterVisibleFile = getFileForDocId(afterDocId, true);
        moveInMediaStore(beforeVisibleFile, afterVisibleFile);
        moveInMediaStore(beforeVisibleFile, afterVisibleFile);