Move building the repo's path logic to one place

Instead of having it duplicated
This commit is contained in:
Vishesh Handa
2020-10-17 12:33:19 +02:00
parent 81bd1322a6
commit 5441700f28
3 changed files with 9 additions and 9 deletions

View File

@ -69,7 +69,7 @@ class JournalApp extends StatefulWidget {
await settings.migrate(pref, appState.gitBaseDirectory);
var gitRepoDir = p.join(appState.gitBaseDirectory, settings.folderName);
var gitRepoDir = settings.buildRepoPath(appState.gitBaseDirectory);
var repoDirStat = File(gitRepoDir).statSync();
if (repoDirStat.type != FileSystemEntityType.directory) {

View File

@ -333,6 +333,12 @@ class Settings extends ChangeNotifier {
}
}
}
String buildRepoPath(String internalDir) {
return storeInternally
? p.join(internalDir, folderName)
: p.join(storageLocation, folderName);
}
}
class NoteFileNameFormat {

View File

@ -43,10 +43,7 @@ class StateContainer with ChangeNotifier {
@required this.gitBaseDirectory,
@required this.cacheDirectory,
}) {
var folderName = settings.folderName;
repoPath = settings.storeInternally
? p.join(gitBaseDirectory, folderName)
: p.join(settings.storageLocation, folderName);
repoPath = settings.buildRepoPath(appState.gitBaseDirectory);
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
appState.notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath, settings);
@ -358,10 +355,7 @@ class StateContainer with ChangeNotifier {
}
Future<void> moveRepoToPath() async {
var folderName = settings.folderName;
var newRepoPath = settings.storeInternally
? p.join(gitBaseDirectory, folderName)
: p.join(settings.storageLocation, folderName);
var newRepoPath = settings.buildRepoPath(appState.gitBaseDirectory);
if (newRepoPath != repoPath) {
Log.i("Old Path: $repoPath");