Copying or moving a folder into itself fails but leaves an empty subfolder behind
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
Research direction
Start in app/src/main/java/com/amaze/filemanager/asynchronous/services/CopyService.java, at Copy.copyFiles around lines 482-495, and inspect the directory handling and Operations.isCopyLoopPossible check. Reproduce copying or moving a folder into itself, then verify the failed operation leaves no newly created subfolder behind for either action.
Written by the indexing model from the issue text.
Description
Describe the bug
When a folder is cut or copied and then pasted into itself, Amaze correctly refuses with "Operation Unsuccessful – Operation failed for following files: 1. sub". However, an empty folder with the same name has already been created inside the source folder (sub/sub). This happens for both Copy and Move.
To Reproduce
Steps to reproduce the behavior:
- In a folder, long-press (or use ⋮ on) the folder
suband choose "Cut" (or "Copy"). - Open
sub. - Tap "PASTE" at the bottom.
- Dismiss the "Operation Unsuccessful" dialog.
- Look at the contents of
sub: there is a new empty foldersub, and the count shows "1 folders and 2 files".
On disk:
sub:
deep.txt notes.txt sub <- new empty folder
Expected behavior
The copy loop is detected and the operation is refused without any side effect. No folder is created.
Screenshots
| Move into itself: "Operation Unsuccessful" | After the failure, sub contains a new empty sub |
Copy into itself fails the same way and also leaves the folder |
|---|---|---|
Smartphone (please complete the following information):
- OS: Android 11 (API 30)
- Rooted: No
- Version: 3.11.3 (versionCode 125)
Additional context
In CopyService.DoInBackground.Copy.copyFiles (CopyService.java#L482-L495), the target folder is created before the copy-loop check:
if (sourceFile.isDirectory()) {
if (!targetFile.exists()) {
targetFile.mkdir(c);
}
// various checks
// 1. source file and target file doesn't end up in loop
// 2. source file has a valid name or not
if (!Operations.isFileNameValid(sourceFile.getName(c))
|| Operations.isCopyLoopPossible(sourceFile, targetFile)) {
failedFOps.add(sourceFile);
return;
}
mkdir runs before Operations.isCopyLoopPossible, and the failure path does not remove the created folder. Moving the check before mkdir (or cleaning up on failure) should fix it.
- Dominant language
- Kotlin
- Stars
- 6.4k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TeamAmaze/AmazeFileManager
-
Area-UIUX Issue-Bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
TeamAmaze/AmazeFileManager#4723 · 4 comments ·
-
Area-FileOperations Issue-Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
TeamAmaze/AmazeFileManager#4131 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
TeamAmaze/AmazeFileManager#4730 ·
-
Corrupt-delete fileOpenArea-FileOperations help wanted Issue-Feature
Difficulty 4/5 3-5 days Newbie friendliness 38/100
TeamAmaze/AmazeFileManager#4721 · 8 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
TeamAmaze/AmazeFileManager#4720 ·
All issues in TeamAmaze/AmazeFileManager
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
recloudstream/cloudstream#3226 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Kotlin/kotlinx.serialization#3277 · 2 reactions ·
Maintainers usually reply within 1 day