Fix database import

This commit is contained in:
Isira Seneviratne 2025-08-25 14:32:19 +05:30 committed by Aayush Gupta
parent aba2a385fd
commit 5f1a270ca4
4 changed files with 19 additions and 20 deletions

View file

@ -67,9 +67,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment {
@Override
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
@Nullable final String rootKey) {
final var dbDir = requireContext().getDatabasePath(BackupFileLocator.FILE_NAME_DB).toPath()
.getParent();
manager = new ImportExportManager(new BackupFileLocator(dbDir));
manager = new ImportExportManager(new BackupFileLocator(requireContext()));
importExportDataPathKey = getString(R.string.import_export_data_path);

View file

@ -1,12 +1,13 @@
package org.schabi.newpipe.settings.export
import android.content.Context
import java.nio.file.Path
import kotlin.io.path.div
/**
* Locates specific files of NewPipe based on the home directory of the app.
*/
class BackupFileLocator(homeDir: Path) {
class BackupFileLocator(context: Context) {
companion object {
const val FILE_NAME_DB = "newpipe.db"
@ -18,9 +19,8 @@ class BackupFileLocator(homeDir: Path) {
const val FILE_NAME_JSON_PREFS = "preferences.json"
}
val dbDir = homeDir / "databases"
val db = homeDir / FILE_NAME_DB
val dbJournal = homeDir / "$FILE_NAME_DB-journal"
val dbShm = dbDir / "$FILE_NAME_DB-shm"
val dbWal = dbDir / "$FILE_NAME_DB-wal"
val db: Path = context.getDatabasePath(FILE_NAME_DB).toPath()
val dbJournal: Path = db.resolveSibling("$FILE_NAME_DB-journal")
val dbShm: Path = db.resolveSibling("$FILE_NAME_DB-shm")
val dbWal: Path = db.resolveSibling("$FILE_NAME_DB-wal")
}

View file

@ -9,7 +9,7 @@ import java.io.FileNotFoundException
import java.io.IOException
import java.io.ObjectOutputStream
import java.util.zip.ZipOutputStream
import kotlin.io.path.createDirectories
import kotlin.io.path.createParentDirectories
import kotlin.io.path.deleteIfExists
import org.schabi.newpipe.streams.io.SharpOutputStream
import org.schabi.newpipe.streams.io.StoredFileHelper
@ -63,7 +63,7 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
*/
@Throws(IOException::class)
fun ensureDbDirectoryExists() {
fileLocator.dbDir.createDirectories()
fileLocator.db.createParentDirectories()
}
/**