Stop always opening files in write mode
This commit is contained in:
parent
8c9c6a20b9
commit
49ec2eaf49
@ -481,8 +481,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener {
|
||||
CustomAlertDialogBuilder(this@CameraActivity, theme)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(R.string.picture_save_failed)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok) { _, _ -> finish() }
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@ -502,6 +501,15 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener {
|
||||
videoRecording?.stop()
|
||||
} else if (!isWaitingForTimer) {
|
||||
val path = getOutputPath(true)
|
||||
val fileHandle = encryptedVolume.openFileWriteMode(path)
|
||||
if (fileHandle == -1L) {
|
||||
CustomAlertDialogBuilder(this, theme)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(R.string.file_creation_failed)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
startTimerThen {
|
||||
var withAudio = true
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@ -513,7 +521,6 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener {
|
||||
this,
|
||||
MuxerOutputOptions(
|
||||
FFmpegMuxer(object : SeekableWriter {
|
||||
private val fileHandle = encryptedVolume.openFile(path)
|
||||
private var offset = 0L
|
||||
|
||||
override fun close() {
|
||||
|
@ -241,7 +241,7 @@ class ExplorerActivity : BaseExplorerActivity() {
|
||||
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
val filePath = PathUtils.pathJoin(currentDirectoryPath, fileName)
|
||||
val handleID = encryptedVolume.openFile(filePath)
|
||||
val handleID = encryptedVolume.openFileWriteMode(filePath)
|
||||
if (handleID == -1L) {
|
||||
CustomAlertDialogBuilder(this, theme)
|
||||
.setTitle(R.string.error)
|
||||
|
@ -125,9 +125,9 @@ class FileOperationService : Service() {
|
||||
|
||||
private fun copyFile(srcPath: String, dstPath: String, remoteEncryptedVolume: EncryptedVolume = encryptedVolume): Boolean {
|
||||
var success = true
|
||||
val srcFileHandle = remoteEncryptedVolume.openFile(srcPath)
|
||||
val srcFileHandle = remoteEncryptedVolume.openFileReadMode(srcPath)
|
||||
if (srcFileHandle != -1L) {
|
||||
val dstFileHandle = encryptedVolume.openFile(dstPath)
|
||||
val dstFileHandle = encryptedVolume.openFileWriteMode(dstPath)
|
||||
if (dstFileHandle != -1L) {
|
||||
var offset: Long = 0
|
||||
val ioBuffer = ByteArray(Constants.IO_BUFF_SIZE)
|
||||
|
@ -15,7 +15,7 @@ class EncryptedVolumeDataSource(private val encryptedVolume: EncryptedVolume, pr
|
||||
private var bytesRemaining: Long = -1
|
||||
|
||||
override fun open(dataSpec: DataSpec): Long {
|
||||
fileHandle = encryptedVolume.openFile(filePath)
|
||||
fileHandle = encryptedVolume.openFileReadMode(filePath)
|
||||
fileOffset = dataSpec.position
|
||||
val fileSize = encryptedVolume.getAttr(filePath)!!.size
|
||||
bytesRemaining = if (dataSpec.length == C.LENGTH_UNSET.toLong()) {
|
||||
|
@ -67,7 +67,7 @@ class TextEditor: FileViewerActivity() {
|
||||
private fun save(): Boolean{
|
||||
var success = false
|
||||
val content = editor.text.toString().toByteArray()
|
||||
val fileHandle = encryptedVolume.openFile(filePath)
|
||||
val fileHandle = encryptedVolume.openFileWriteMode(filePath)
|
||||
if (fileHandle != -1L) {
|
||||
var offset: Long = 0
|
||||
while (offset < content.size && encryptedVolume.write(fileHandle, offset, content, offset, content.size.toLong()).also { offset += it } > 0) {}
|
||||
|
@ -94,7 +94,11 @@ class CryfsVolume(private val fusePtr: Long): EncryptedVolume() {
|
||||
writeLong(fusePtr)
|
||||
}
|
||||
|
||||
override fun openFile(path: String): Long {
|
||||
override fun openFileReadMode(path: String): Long {
|
||||
return nativeOpen(fusePtr, path, 0)
|
||||
}
|
||||
|
||||
override fun openFileWriteMode(path: String): Long {
|
||||
val fileHandle = nativeOpen(fusePtr, path, 0)
|
||||
return if (fileHandle == -1L) {
|
||||
nativeCreate(fusePtr, path, 0)
|
||||
|
@ -73,7 +73,8 @@ abstract class EncryptedVolume: Parcelable {
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
abstract fun openFile(path: String): Long
|
||||
abstract fun openFileReadMode(path: String): Long
|
||||
abstract fun openFileWriteMode(path: String): Long
|
||||
abstract fun read(fileHandle: Long, fileOffset: Long, buffer: ByteArray, dstOffset: Long, length: Long): Int
|
||||
abstract fun write(fileHandle: Long, fileOffset: Long, buffer: ByteArray, srcOffset: Long, length: Long): Int
|
||||
abstract fun closeFile(fileHandle: Long): Boolean
|
||||
@ -106,7 +107,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
|
||||
fun exportFile(src_path: String, os: OutputStream): Boolean {
|
||||
var success = false
|
||||
val srcfileHandle = openFile(src_path)
|
||||
val srcfileHandle = openFileReadMode(src_path)
|
||||
if (srcfileHandle != -1L) {
|
||||
success = exportFile(srcfileHandle, os)
|
||||
closeFile(srcfileHandle)
|
||||
@ -127,7 +128,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
}
|
||||
|
||||
fun importFile(inputStream: InputStream, dst_path: String): Boolean {
|
||||
val dstfileHandle = openFile(dst_path)
|
||||
val dstfileHandle = openFileWriteMode(dst_path)
|
||||
if (dstfileHandle != -1L) {
|
||||
var success = true
|
||||
var offset: Long = 0
|
||||
@ -169,7 +170,7 @@ abstract class EncryptedVolume: Parcelable {
|
||||
}
|
||||
try {
|
||||
val fileBuff = ByteArray(fileSize.toInt())
|
||||
val fileHandle = openFile(fullPath)
|
||||
val fileHandle = openFileReadMode(fullPath)
|
||||
if (fileHandle == -1L) {
|
||||
Pair(null, 3)
|
||||
} else {
|
||||
|
@ -91,7 +91,11 @@ class GocryptfsVolume(private val sessionID: Int): EncryptedVolume() {
|
||||
|
||||
constructor(parcel: Parcel) : this(parcel.readInt())
|
||||
|
||||
override fun openFile(path: String): Long {
|
||||
override fun openFileReadMode(path: String): Long {
|
||||
return native_open_read_mode(sessionID, path).toLong()
|
||||
}
|
||||
|
||||
override fun openFileWriteMode(path: String): Long {
|
||||
return native_open_write_mode(sessionID, path, 384).toLong() // 0600
|
||||
}
|
||||
|
||||
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,7 @@
|
||||
#Wed Feb 01 20:48:39 UTC 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionSha256Sum=7ba68c54029790ab444b39d7e293d3236b2632631fb5f2e012bb28b4ff669e4b
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
Loading…
Reference in New Issue
Block a user