Merge pull request #3064 from nextcloud/fileUtilFixes

File util fixes
This commit is contained in:
Marcel Hibbe 2023-06-01 13:30:18 +02:00 committed by GitHub
commit 303e28c154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -126,7 +126,9 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
initNotificationSetup()
if (file != null && file.length() > CHUNK_UPLOAD_THRESHOLD_SIZE) {
if (file == null) {
uploadSuccess = false
} else if (file.length() > CHUNK_UPLOAD_THRESHOLD_SIZE) {
Log.d(TAG, "starting chunked upload because size is " + file.length())
initNotificationWithPercentage()

View File

@ -112,9 +112,15 @@ object FileUtils {
}
@Suppress("NestedBlockDepth")
fun copyFileToCache(context: Context, sourceFileUri: Uri, filename: String): File {
fun copyFileToCache(context: Context, sourceFileUri: Uri, filename: String): File? {
val cachedFile = File(context.cacheDir, filename)
if (!cachedFile.canonicalPath.startsWith(context.cacheDir.canonicalPath, true)) {
Log.w(TAG, "cachedFile was not created in cacheDir. Aborting for security reasons.")
cachedFile.delete()
return null
}
if (cachedFile.exists()) {
Log.d(TAG, "file is already in cache")
} else {
@ -149,11 +155,13 @@ object FileUtils {
// if it was no content uri, read filename from path
if (filename == null) {
filename = uri.path
val lastIndexOfSlash = filename!!.lastIndexOf('/')
if (lastIndexOfSlash != -1) {
filename = filename.substring(lastIndexOfSlash + 1)
}
}
val lastIndexOfSlash = filename!!.lastIndexOf('/')
if (lastIndexOfSlash != -1) {
filename = filename.substring(lastIndexOfSlash + 1)
}
return filename
}