Temporary files are now deleted when exiting the app
This commit is contained in:
parent
762aa7a9d1
commit
fc4d52b57a
20
src/main/kotlin/app/TempFilesManager.kt
Normal file
20
src/main/kotlin/app/TempFilesManager.kt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import app.di.TabScope
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.io.path.createTempDirectory
|
||||||
|
import kotlin.io.path.deleteIfExists
|
||||||
|
|
||||||
|
@TabScope
|
||||||
|
class TempFilesManager @Inject constructor() {
|
||||||
|
val tempDir by lazy {
|
||||||
|
val tempDirPath = createTempDirectory("gitnuro_")
|
||||||
|
tempDirPath.toFile().deleteOnExit()
|
||||||
|
|
||||||
|
tempDirPath
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeTempDir() {
|
||||||
|
tempDir.deleteIfExists()
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package app.git
|
package app.git
|
||||||
|
|
||||||
|
import app.TempFilesManager
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import org.eclipse.jgit.diff.ContentSource
|
import org.eclipse.jgit.diff.ContentSource
|
||||||
@ -14,14 +15,14 @@ import org.eclipse.jgit.util.LfsFactory
|
|||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.absolutePathString
|
import kotlin.io.path.absolutePathString
|
||||||
import kotlin.io.path.createTempDirectory
|
|
||||||
import kotlin.io.path.createTempFile
|
import kotlin.io.path.createTempFile
|
||||||
|
|
||||||
|
|
||||||
private const val DEFAULT_BINARY_FILE_THRESHOLD = PackConfig.DEFAULT_BIG_FILE_THRESHOLD
|
private const val DEFAULT_BINARY_FILE_THRESHOLD = PackConfig.DEFAULT_BIG_FILE_THRESHOLD
|
||||||
|
|
||||||
class RawFileManager @AssistedInject constructor(
|
class RawFileManager @AssistedInject constructor(
|
||||||
@Assisted private val repository: Repository
|
@Assisted private val repository: Repository,
|
||||||
|
private val tempFilesManager: TempFilesManager,
|
||||||
) : AutoCloseable {
|
) : AutoCloseable {
|
||||||
private var reader: ObjectReader = repository.newObjectReader()
|
private var reader: ObjectReader = repository.newObjectReader()
|
||||||
private var source: ContentSource.Pair
|
private var source: ContentSource.Pair
|
||||||
@ -75,8 +76,10 @@ class RawFileManager @AssistedInject constructor(
|
|||||||
): EntryContent.ImageBinary {
|
): EntryContent.ImageBinary {
|
||||||
println("Data's size is ${ldr.size}")
|
println("Data's size is ${ldr.size}")
|
||||||
|
|
||||||
val tempDir = createTempDirectory("gitnuro${repository.directory.absolutePath.replace("/", "_")}")
|
val tempDir = tempFilesManager.tempDir
|
||||||
|
|
||||||
val tempFile = createTempFile(tempDir, prefix = "${entry.newPath.replace("/", "_")}_${side.name}")
|
val tempFile = createTempFile(tempDir, prefix = "${entry.newPath.replace("/", "_")}_${side.name}")
|
||||||
|
tempFile.toFile().deleteOnExit()
|
||||||
println("Temp file generated: ${tempFile.absolutePathString()}")
|
println("Temp file generated: ${tempFile.absolutePathString()}")
|
||||||
|
|
||||||
val out = FileOutputStream(tempFile.toFile())
|
val out = FileOutputStream(tempFile.toFile())
|
||||||
|
Loading…
Reference in New Issue
Block a user