Skip to content

Commit 972aea1

Browse files
committed
fix files not moved when atomic move is not supported
1 parent d5e5671 commit 972aea1

File tree

1 file changed

+22
-8
lines changed
  • app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/files/task

1 file changed

+22
-8
lines changed

app/src/main/java/com/raival/compose/file/explorer/screen/main/tab/files/task/CopyTask.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import net.lingala.zip4j.ZipFile
1515
import net.lingala.zip4j.model.ZipParameters
1616
import java.io.ByteArrayInputStream
1717
import java.io.File
18+
import java.nio.file.AtomicMoveNotSupportedException
1819
import java.nio.file.Files
1920
import java.nio.file.StandardCopyOption
2021

@@ -372,14 +373,27 @@ class CopyTask(
372373
if (source.isFile) {
373374
destination.parentFile?.mkdirs()
374375
if (deleteSourceFiles) {
375-
Files.move(
376-
source.toPath(),
377-
destination.toPath(),
378-
*buildList {
379-
add(StandardCopyOption.ATOMIC_MOVE)
380-
if (overwrite) add(StandardCopyOption.REPLACE_EXISTING)
381-
}.toTypedArray()
382-
)
376+
try {
377+
// Try atomic move first (faster when supported)
378+
Files.move(
379+
source.toPath(),
380+
destination.toPath(),
381+
*buildList {
382+
add(StandardCopyOption.ATOMIC_MOVE)
383+
if (overwrite) add(StandardCopyOption.REPLACE_EXISTING)
384+
}.toTypedArray()
385+
)
386+
} catch (_: AtomicMoveNotSupportedException) {
387+
// Fallback to copy only - deletion will be handled by performSourceDeletion()
388+
Files.copy(
389+
source.toPath(),
390+
destination.toPath(),
391+
*buildList {
392+
add(StandardCopyOption.COPY_ATTRIBUTES)
393+
if (overwrite) add(StandardCopyOption.REPLACE_EXISTING)
394+
}.toTypedArray()
395+
)
396+
}
383397
} else {
384398
source.copyTo(destination, overwrite)
385399
}

0 commit comments

Comments
 (0)