remove all mentions of getWorkTree

This commit is contained in:
Mohamed Zenadi
2017-01-16 20:32:46 +01:00
parent 0f7c933565
commit b6f5421d67
9 changed files with 17 additions and 29 deletions

View File

@@ -221,7 +221,7 @@ public class PasswordFragment extends Fragment{
*/ */
public File getCurrentDir() { public File getCurrentDir() {
if (pathStack.isEmpty()) if (pathStack.isEmpty())
return PasswordRepository.getWorkTree(); return PasswordRepository.getRepositoryDirectory(getActivity().getApplicationContext());
else else
return pathStack.peek(); return pathStack.peek();
} }

View File

@@ -272,7 +272,7 @@ public class PasswordStore extends AppCompatActivity {
PasswordRepository.initialize(this); PasswordRepository.initialize(this);
} }
File localDir = PasswordRepository.getWorkTree(); File localDir = PasswordRepository.getRepositoryDirectory(getApplicationContext());
localDir.mkdir(); localDir.mkdir();
try { try {
@@ -329,7 +329,7 @@ public class PasswordStore extends AppCompatActivity {
intent.putExtra("operation", "git_external"); intent.putExtra("operation", "git_external");
startActivityForResult(intent, HOME); startActivityForResult(intent, HOME);
} else { } else {
checkLocalRepository(PasswordRepository.getWorkTree()); checkLocalRepository(PasswordRepository.getRepositoryDirectory(getApplicationContext()));
} }
} }
@@ -344,7 +344,7 @@ public class PasswordStore extends AppCompatActivity {
plist = new PasswordFragment(); plist = new PasswordFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath()); args.putString("Path", PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath());
// if the activity was started from the autofill settings, the // if the activity was started from the autofill settings, the
// intent is to match a clicked pwd with app. pass this to fragment // intent is to match a clicked pwd with app. pass this to fragment
@@ -510,7 +510,7 @@ public class PasswordStore extends AppCompatActivity {
if ((null != plist)) { if ((null != plist)) {
return plist.getCurrentDir(); return plist.getCurrentDir();
} }
return PasswordRepository.getWorkTree(); return PasswordRepository.getRepositoryDirectory(getApplicationContext());
} }
private void commit(final String message) { private void commit(final String message) {
@@ -604,9 +604,9 @@ public class PasswordStore extends AppCompatActivity {
Log.e("Moving", "Something went wrong while moving."); Log.e("Moving", "Something went wrong while moving.");
} else { } else {
commit("[ANDROID PwdStore] Moved " commit("[ANDROID PwdStore] Moved "
+ string.replace(PasswordRepository.getWorkTree() + "/", "") + string.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/", "")
+ " to " + " to "
+ target.getAbsolutePath().replace(PasswordRepository.getWorkTree() + "/", "") + target.getAbsolutePath().replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/", "")
+ target.getAbsolutePath() + "/" + source.getName() + "."); + target.getAbsolutePath() + "/" + source.getName() + ".");
} }
} }
@@ -685,7 +685,7 @@ public class PasswordStore extends AppCompatActivity {
public void matchPasswordWithApp(PasswordItem item) { public void matchPasswordWithApp(PasswordItem item) {
String path = item.getFile().getAbsolutePath(); String path = item.getFile().getAbsolutePath();
path = path.replace(PasswordRepository.getWorkTree() + "/", "").replace(".gpg", ""); path = path.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/", "").replace(".gpg", "");
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("path", path); data.putExtra("path", path);
setResult(RESULT_OK, data); setResult(RESULT_OK, data);

View File

@@ -216,7 +216,7 @@ public class SelectFolderFragment extends Fragment{
*/ */
public File getCurrentDir() { public File getCurrentDir() {
if (pathStack.isEmpty()) if (pathStack.isEmpty())
return PasswordRepository.getWorkTree(); return PasswordRepository.getRepositoryDirectory(getActivity().getApplicationContext());
else else
return pathStack.peek(); return pathStack.peek();
} }

View File

@@ -118,13 +118,13 @@ public class UserPreference extends AppCompatActivity {
new AlertDialog.Builder(callingActivity). new AlertDialog.Builder(callingActivity).
setTitle(R.string.pref_dialog_delete_title). setTitle(R.string.pref_dialog_delete_title).
setMessage(getResources().getString(R.string.dialog_delete_msg) setMessage(getResources().getString(R.string.dialog_delete_msg)
+ " \n" + PasswordRepository.getWorkTree().toString()). + " \n" + PasswordRepository.getRepositoryDirectory(callingActivity.getApplicationContext()).toString()).
setCancelable(false). setCancelable(false).
setPositiveButton(R.string.dialog_delete, new DialogInterface.OnClickListener() { setPositiveButton(R.string.dialog_delete, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
try { try {
FileUtils.cleanDirectory(PasswordRepository.getWorkTree()); FileUtils.cleanDirectory(PasswordRepository.getRepositoryDirectory(callingActivity.getApplicationContext()));
PasswordRepository.closeRepository(); PasswordRepository.closeRepository();
} catch (Exception e) { } catch (Exception e) {
//TODO Handle the diffent cases of exceptions //TODO Handle the diffent cases of exceptions

View File

@@ -69,7 +69,7 @@ public class AutofillService extends AccessibilityService {
public void setResultData(Intent data) { resultData = data; } public void setResultData(Intent data) { resultData = data; }
public void setPickedPassword(String path) { public void setPickedPassword(String path) {
items.add(new File(PasswordRepository.getWorkTree() + "/" + path + ".gpg")); items.add(new File(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/" + path + ".gpg"));
bindDecryptAndVerify(); bindDecryptAndVerify();
} }
@@ -334,7 +334,7 @@ public class AutofillService extends AccessibilityService {
String preferredPasswords[] = preference.split("\n"); String preferredPasswords[] = preference.split("\n");
items = new ArrayList<>(); items = new ArrayList<>();
for (String password : preferredPasswords) { for (String password : preferredPasswords) {
String path = PasswordRepository.getWorkTree() + "/" + password + ".gpg"; String path = PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/" + password + ".gpg";
if (new File(path).exists()) { if (new File(path).exists()) {
items.add(new File(path)); items.add(new File(path));
} }

View File

@@ -457,7 +457,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
passwordList = new SelectFolderFragment(); passwordList = new SelectFolderFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath()); args.putString("Path", PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath());
passwordList.setArguments(args); passwordList.setArguments(args);
@@ -751,7 +751,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface); ((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface);
((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface); ((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface);
String cat = extra.getString("FILE_PATH"); String cat = extra.getString("FILE_PATH");
cat = cat.replace(PasswordRepository.getWorkTree().getAbsolutePath(), ""); cat = cat.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), "");
cat = cat + "/"; cat = cat + "/";
((TextView) findViewById(R.id.crypto_password_category)).setText(cat); ((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
} else if (operation.equals("GET_KEY_ID")) { } else if (operation.equals("GET_KEY_ID")) {
@@ -765,7 +765,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
} else if (operation.equals("EDIT")) { } else if (operation.equals("EDIT")) {
setContentView(R.layout.decrypt_layout); setContentView(R.layout.decrypt_layout);
((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME")); ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
String cat = new File(extra.getString("FILE_PATH").replace(PasswordRepository.getWorkTree().getAbsolutePath(), "")) String cat = new File(extra.getString("FILE_PATH").replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), ""))
.getParentFile().getName(); .getParentFile().getName();
((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/"); ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");

View File

@@ -5,9 +5,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@@ -86,12 +84,6 @@ public class CloneOperation extends GitOperation {
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
// if we were unable to finish the job
try {
FileUtils.deleteDirectory(PasswordRepository.getWorkTree());
} catch (Exception e) {
e.printStackTrace();
}
} }
}).show(); }).show();
} }

View File

@@ -470,7 +470,7 @@ public class GitActivity extends AppCompatActivity {
if (PasswordRepository.getRepository(null) == null) { if (PasswordRepository.getRepository(null) == null) {
PasswordRepository.initialize(this); PasswordRepository.initialize(this);
} }
localDir = PasswordRepository.getWorkTree(); localDir = PasswordRepository.getRepositoryDirectory(context);
if (!saveConfiguration()) if (!saveConfiguration())
return; return;

View File

@@ -159,10 +159,6 @@ public class PasswordRepository {
return getPasswords(rootDir, rootDir); return getPasswords(rootDir, rootDir);
} }
public static File getWorkTree() {
return repository.getWorkTree();
}
/** /**
* Gets the .gpg files in a directory * Gets the .gpg files in a directory
* @param path the directory path * @param path the directory path