Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
if (cancellationRequested.get()) return RemoteOperationResult(OperationCancelledException())
}

if (file.isFolder) {
Log_OC.e(TAG, "Cannot download a folder as a file: ${file.remotePath}")
return RemoteOperationResult(RemoteOperationResult.ResultCode.CANNOT_CREATE_FILE)
}

if (!FileStorageUtils.isValidExtFilename(file.fileName)) {
mainThreadHandler.post { context.get()?.showToast(R.string.download_download_invalid_local_file_name) }
return RemoteOperationResult(RemoteOperationResult.ResultCode.INVALID_CHARACTER_IN_NAME)
Expand Down Expand Up @@ -213,11 +218,21 @@
)
}

private fun ensureParentDirectory(target: File) {
val parent = target.parentFile ?: return

if (parent.exists() && !parent.isDirectory && !parent.delete()) {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
Log_OC.e(TAG, "Unable to delete file blocking parent folder ${parent.absolutePath}")
}

if (!parent.exists() && !parent.mkdirs()) {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
Log_OC.e(TAG, "Unable to create parent folder ${parent.absolutePath}")
}
}

private fun handleFileMove(tmpFile: File, currentResult: RemoteOperationResult<Unit>): RemoteOperationResult<Unit> {
val newFile = File(savePath)
newFile.parentFile?.takeIf { !it.exists() }?.also {
if (!it.mkdirs()) Log_OC.e(TAG, "Unable to create parent folder ${it.absolutePath}")
}
ensureParentDirectory(newFile)

val tempFilePath = tmpFile.toPath()
val newFilePath = newFile.toPath()
Expand Down
Loading
Loading