Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Copying or moving a folder into itself fails but leaves an empty subfolder behind

Open Beginner friendly
#4,731 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, java
Domain
mobile

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:

  1. In a folder, long-press (or use ⋮ on) the folder sub and choose "Cut" (or "Copy").
  2. Open sub.
  3. Tap "PASTE" at the bottom.
  4. Dismiss the "Operation Unsuccessful" dialog.
  5. Look at the contents of sub: there is a new empty folder sub, 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
Move into itself dialog Stray empty folder Copy into itself dialog

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TeamAmaze/AmazeFileManager

All issues in TeamAmaze/AmazeFileManager

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.