Skip to content
New issue

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

Fix broken ignore rule check in GitRepo.storeBook() #265

Merged
Merged
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
14 changes: 10 additions & 4 deletions app/src/main/java/com/orgzly/android/repos/GitRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public boolean isAutoSyncSupported() {
}

public VersionedRook storeBook(File file, String fileName) throws IOException {
ensureFileNameIsNotIgnored(fileName);
File destination = synchronizer.repoDirectoryFile(fileName);
ensureRepoPathIsNotIgnored(destination.getPath());

if (destination.exists()) {
synchronizer.updateAndCommitExistingFile(file, fileName);
Expand Down Expand Up @@ -248,9 +248,15 @@ private IgnoreNode getIgnores() throws IOException {
return ignores;
}

private void ensureRepoPathIsNotIgnored(String filePath) throws IOException {
/**
* Since subdirectories are currently not supported, we only check the file name against the
* ignore rules.
* @param fileName Name of the file which the user tries to write to
* @throws IOException
*/
private void ensureFileNameIsNotIgnored(String fileName) throws IOException {
IgnoreNode ignores = getIgnores();
if (ignores.isIgnored(filePath, false) == IgnoreNode.MatchResult.IGNORED) {
if (ignores.isIgnored(fileName, false) == IgnoreNode.MatchResult.IGNORED) {
throw new IOException(context.getString(R.string.error_file_matches_repo_ignore_rule,
context.getString(R.string.repo_ignore_rules_file)));
}
Expand Down Expand Up @@ -323,7 +329,7 @@ public void delete(Uri uri) throws IOException {
public VersionedRook renameBook(Uri oldUri, String newRookName) throws IOException {
String oldFileName = oldUri.toString().replaceFirst("^/", "");
String newFileName = newRookName + ".org";
ensureRepoPathIsNotIgnored(newFileName);
ensureFileNameIsNotIgnored(newFileName);
if (synchronizer.renameFileInRepo(oldFileName, newFileName)) {
synchronizer.tryPush();
return currentVersionedRook(Uri.EMPTY.buildUpon().appendPath(newFileName).build());
Expand Down
Loading