Merge pull request #62719 from m4gr3d/fix_directory_copy_bug_3x
Fix the directory copy bug issue
This commit is contained in:
commit
0cc154b120
2 changed files with 17 additions and 5 deletions
|
@ -103,6 +103,8 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract val fileChannel: FileChannel
|
protected abstract val fileChannel: FileChannel
|
||||||
|
internal var endOfFile = false
|
||||||
|
private set
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
try {
|
try {
|
||||||
|
@ -123,6 +125,9 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||||
fun seek(position: Long) {
|
fun seek(position: Long) {
|
||||||
try {
|
try {
|
||||||
fileChannel.position(position)
|
fileChannel.position(position)
|
||||||
|
if (position <= size()) {
|
||||||
|
endOfFile = false
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "Exception when seeking file $filePath.", e)
|
Log.w(TAG, "Exception when seeking file $filePath.", e)
|
||||||
}
|
}
|
||||||
|
@ -153,11 +158,15 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||||
0L
|
0L
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEndOfFile() = position() >= size()
|
|
||||||
|
|
||||||
fun read(buffer: ByteBuffer): Int {
|
fun read(buffer: ByteBuffer): Int {
|
||||||
return try {
|
return try {
|
||||||
fileChannel.read(buffer)
|
val readBytes = fileChannel.read(buffer)
|
||||||
|
if (readBytes == -1) {
|
||||||
|
endOfFile = true
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
readBytes
|
||||||
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.w(TAG, "Exception while reading from file $filePath.", e)
|
Log.w(TAG, "Exception while reading from file $filePath.", e)
|
||||||
0
|
0
|
||||||
|
@ -166,7 +175,10 @@ internal abstract class DataAccess(private val filePath: String) {
|
||||||
|
|
||||||
fun write(buffer: ByteBuffer) {
|
fun write(buffer: ByteBuffer) {
|
||||||
try {
|
try {
|
||||||
fileChannel.write(buffer)
|
val writtenBytes = fileChannel.write(buffer)
|
||||||
|
if (writtenBytes > 0) {
|
||||||
|
endOfFile = false
|
||||||
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.w(TAG, "Exception while writing to file $filePath.", e)
|
Log.w(TAG, "Exception while writing to file $filePath.", e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ class FileAccessHandler(val context: Context) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return files[fileId].isEndOfFile()
|
return files[fileId].endOfFile
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fileClose(fileId: Int) {
|
fun fileClose(fileId: Int) {
|
||||||
|
|
Loading…
Reference in a new issue