8000 Implemented: Move file storage out of sandbox by van-gog · Pull Request #18 · andrewromanenco/git.android · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implemented: Move file storage out of sandbox #18

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/com/romanenco/gitt/BrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void updateTitleWithPath() {
int index = path.lastIndexOf("/");
if (index == -1) {
//reading branch name in main thread...
String branch = GitHelper.currentBranchName(this.getFilesDir() + "/" + current.getFolder());
String branch = GitHelper.currentBranchName(GitHelper.getBaseRepoDir(this, current.getFolder()) + "/" + current.getFolder());
this.setTitle("(" + branch + ")/.");
} else {
this.setTitle(".." + path.substring(index));
Expand All @@ -171,7 +171,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
getListView().setAdapter(adapter);
} else {
Intent next = new Intent(this, CodeViewActivity.class);
File file = new File(this.getFilesDir(), current.getFolder());
File file = new File(GitHelper.getBaseRepoDir(this, current.getFolder()), current.getFolder());
file = new File(file, path);
file = new File(file, adapter.getItem(position));
next.putExtra(CodeViewActivity.FILE_KEY, file);
Expand Down Expand Up @@ -344,21 +344,23 @@ public FileListAdapter(Context context, Repo repo, String folder) {
Log.d(TAG, "Reading: " + folder);
this.context = context;
browseCache.put(repo.getFolder(), folder);
File repoDir = new File(context.getFilesDir(), repo.getFolder());
File repoDir = new File(GitHelper.getBaseRepoDir(context, current.getFolder()), repo.getFolder());
File dir = new File(repoDir, folder);
File[] files = dir.listFiles();
Arrays.sort(files, NameFileComparator.NAME_COMPARATOR);
allItems = new ArrayList<Item>();
fileSizes = new HashMap<String, String>();
if (!folder.equals(".")) {
allItems.add(new Item("..", true));
}
for (File f: files) {
if (".git".equals(f.getName())) continue;
boolean isDir = f.isDirectory();
allItems.add(new Item(f.getName(), isDir));
if (!isDir) {
fileSizes.put(f.getName(), Utils.formatFileSize(BrowserActivity.this, f.length()));
if (dir.exists()) { // prevent crash if repo folder was deleted
File[] files = dir.listFiles();
Arrays.sort(files, NameFileComparator.NAME_COMPARATOR);
fileSizes = new HashMap<String, String>();
if (!folder.equals(".")) {
allItems.add(new Item("..", true));
}
for (File f: files) {
if (".git".equals(f.getName())) continue;
boolean isDir = f.isDirectory();
allItems.add(new Item(f.getName(), isDir));
if (!isDir) {
fileSizes.put(f.getName(), Utils.formatFileSize(BrowserActivity.this, f.length()));
}
}
}
filteredList = allItems;
Expand Down
2 changes: 1 addition & 1 deletion src/com/romanenco/gitt/CheckoutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RepoBranchesAndTagsAdapter extends BaseAdapter {
padding_px = (int) (padding_dp * scale + 0.5f);

list = new ArrayList<String>();
GitHelper.readBranchesAndTags(list, getFilesDir() + "/"
GitHelper.readBranchesAndTags(list, GitHelper.getBaseRepoDir(CheckoutActivity.this, repo.getFolder()) + "/"
+ repo.getFolder());
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/romanenco/gitt/CloneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void deleteGitRepo() {
dao.open(true);
dao.delete(current.getFolder());
try {
GitHelper.deleteRepo(getFilesDir() + "/" + current.getFolder());
GitHelper.deleteRepo(GitHelper.getBaseRepoDir(this, current.getFolder()) + "/" + current.getFolder());
} catch (IOException e) {
} // no need to handle
dao.close();
Expand Down
8 changes: 4 additions & 4 deletions src/com/romanenco/gitt/GitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void clone(Intent intent) {

Log.d(TAG, "Starting processing: " + repo.getName());

String path = this.getFilesDir().getPath() + "/" + repo.getFolder();
String path = GitHelper.getBaseRepoDir(this, repo.getFolder()).getPath() + "/" + repo.getFolder();
ProgressMonitor pm = new Progress(repo.getFolder());

try {
Expand Down Expand Up @@ -190,7 +190,7 @@ private void clone(Intent intent) {
*/
private void delete(Intent intent) {
Repo repo = (Repo) intent.getSerializableExtra(REPO);
String path = this.getFilesDir().getPath() + "/" + repo.getFolder();
String path = GitHelper.getBaseRepoDir(this, repo.getFolder()).getPath() + "/" + repo.getFolder();
try {
GitHelper.deleteRepo(path);
} catch (IOException e) {
Expand All @@ -207,7 +207,7 @@ private void delete(Intent intent) {
*/
private void checkout(Intent intent) {
Repo repo = (Repo) intent.getSerializableExtra(REPO);
String path = this.getFilesDir().getPath() + "/" + repo.getFolder();
String path = GitHelper.getBaseRepoDir(this, repo.getFolder()).getPath() + "/" + repo.getFolder();
String branchOrTag = intent.getStringExtra(SWITCH_TO);
try {
GitHelper.checkout(path, branchOrTag);
Expand All @@ -231,7 +231,7 @@ private void checkout(Intent intent) {
*/
private void pull(Intent intent) {
Repo repo = (Repo) intent.getSerializableExtra(REPO);
String path = this.getFilesDir().getPath() + "/" + repo.getFolder();
String path = GitHelper.getBaseRepoDir(this, repo.getFolder()).getPath() + "/" + repo.getFolder();
ProgressMonitor pm = new Progress(repo.getFolder());
String passwd = intent.getStringExtra(AUTH_PASSWD);

Expand Down
2 changes: 1 addition & 1 deletion src/com/romanenco/gitt/LogViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {

textView = (TextView)findViewById(R.id.text_log);
textView.setMovementMethod(new ScrollingMovementMethod());
File repoDir = new File(this.getFilesDir(), current.getFolder());
File repoDir = new File(GitHelper.getBaseRepoDir(this, current.getFolder()), current.getFolder());

new LogReaderTask().execute(repoDir);
}
Expand Down
42 changes: 42 additions & 0 deletions src/com/romanenco/gitt/git/GitHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import com.romanenco.gitt.GittApp;
Expand Down Expand Up @@ -313,6 +315,46 @@ public static List<LogEntry> readRepoHistory(String repoPath, int maxRecords) {
return result;
}

/**
* Create base repository directory on SD card
*
* @param Context context
* @return File
*/
public static File getBaseRepoDir(Context context)
{
return getBaseRepoDir(context, "");
}

/**
* Create base repository directory on SD card
*
* @param Context context
* @param String repoDir
* @return File
*/
public static File getBaseRepoDir(Context context, String repoDir)
{
if (repoDir != "") {
File internalStorage = new File(context.getFilesDir(), repoDir);
if (internalStorage.exists()) {
return context.getFilesDir();
}
}
File sdCardRoot = Environment.getExternalStorageDirectory();
File repoRoot = new File(sdCardRoot + "/gitt");
try {
if (!repoRoot.exists() || !repoRoot.isDirectory()) {
if (!repoRoot.mkdirs()) {
throw new IOException("Could not create directory for repos.");
}
}
} catch (IOException e) {
Log.e(TAG, "IO", e);
}
return repoRoot;
}

/**
* Log entry.
*
Expand Down
0