Skip to content

Commit c2a90f5

Browse files
committed
handle AccessDeniedException when moving files on external storage
1 parent a4669e5 commit c2a90f5

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ android {
4141
else -> 0
4242
}
4343

44-
val vCode = 430
44+
val vCode = 433
4545
versionCode = vCode - singleAbiNum
46-
versionName = "2.1.15"
46+
versionName = "2.1.16"
4747

4848
ndk {
4949
//noinspection ChromeOsAbiSupport

app/src/main/java/com/ismartcoding/plain/ui/page/files/components/FilePasteBar.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,26 @@ fun FilePasteBar(
8383
}
8484

8585
val dstFile = File(dstCanonical, srcCanonical.name)
86-
if (!dstFile.exists()) {
87-
srcCanonical.toPath().moveTo(dstFile.toPath(), true)
88-
} else {
89-
srcCanonical.toPath().moveTo(Path(dstFile.newPath()), true)
86+
try {
87+
if (!dstFile.exists()) {
88+
srcCanonical.toPath().moveTo(dstFile.toPath(), true)
89+
} else {
90+
srcCanonical.toPath().moveTo(Path(dstFile.newPath()), true)
91+
}
92+
} catch (e: Exception) {
93+
// Fallback: copy then delete (handles cross-filesystem moves)
94+
try {
95+
val target = if (!dstFile.exists()) dstFile else File(dstFile.newPath())
96+
if (srcCanonical.isDirectory) {
97+
srcCanonical.copyRecursively(target, true)
98+
srcCanonical.deleteRecursively()
99+
} else {
100+
srcCanonical.copyTo(target, true)
101+
srcCanonical.delete()
102+
}
103+
} catch (ex: Exception) {
104+
DialogHelper.showErrorMessage(ex.message ?: LocaleHelper.getString(R.string.unknown_error))
105+
}
90106
}
91107
}
92108
filesVM.cutFiles.clear()
@@ -113,10 +129,14 @@ fun FilePasteBar(
113129
}
114130

115131
val dstFile = File(dstCanonical, srcCanonical.name)
116-
if (!dstFile.exists()) {
117-
srcCanonical.copyRecursively(dstFile, true)
118-
} else {
119-
srcCanonical.copyRecursively(File(dstFile.newPath()), true)
132+
try {
133+
if (!dstFile.exists()) {
134+
srcCanonical.copyRecursively(dstFile, true)
135+
} else {
136+
srcCanonical.copyRecursively(File(dstFile.newPath()), true)
137+
}
138+
} catch (e: Exception) {
139+
DialogHelper.showErrorMessage(e.message ?: LocaleHelper.getString(R.string.unknown_error))
120140
}
121141
}
122142
filesVM.copyFiles.clear()

0 commit comments

Comments
 (0)