Skip to content

Commit

Permalink
make getBooks() only list either encrypted or unencrypted books
Browse files Browse the repository at this point in the history
  • Loading branch information
heinzelotto committed May 10, 2020
1 parent 8f4ef24 commit 529ecf9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/orgzly/android/BookName.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BookName {

private static final Pattern PATTERN = Pattern.compile("(.*)\\.(org)(\\.txt)?(\\.gpg)?$");
private static final Pattern SKIP_PATTERN = Pattern.compile("^\\.#.*");
private static final Pattern GPG_PATTERN = Pattern.compile("(.*)(\\.gpg)$");

private final String mFileName;
private final String mName;
Expand Down Expand Up @@ -71,6 +72,10 @@ public static boolean isSupportedFormatFileName(String fileName) {
return PATTERN.matcher(fileName).matches() && !SKIP_PATTERN.matcher(fileName).matches();
}

public static boolean isEncryptedSupportedFormatFileName(String fileName) {
return isSupportedFormatFileName(fileName) && GPG_PATTERN.matcher(fileName).matches();
}

public static String fileName(String name, BookFormat format) {
if (format == BookFormat.ORG) {
return name + ".org";
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/orgzly/android/data/DataRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class DataRepository @Inject constructor(
Pair(tmpFileEncrypted, MiscUtils.ensureGpgExtensionFileName(fileName))
} else {
// remove possible .gpg extension left over from a previous encrypted sync
// ?maybe move this logic to BookView.getFileName()
Pair(tmpFile, MiscUtils.ensureNoGpgExtensionFileName(fileName))
}

Expand Down Expand Up @@ -1584,9 +1583,6 @@ class DataRepository @Inject constructor(
val tmpFileDecrypted = getTempBookFile()
try {
/* Download from repo. */
// ensure that we don't try to decrypt .org files or interpret .org.gpg as plaintext
// problem if both 'nb.org' and 'nb.org.gpg' exist. probably some other mechanism that
// runs at a higher level that here should be made aware and responsible of .pgp extensions
val toRecvFileName = if (repo.isEncryptionEnabled) {
MiscUtils.ensureGpgExtensionFileName(fileName)
} else {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/orgzly/android/repos/DropboxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void deleteToken() {
AppPreferences.dropboxToken(mContext, null);
}

public List<VersionedRook> getBooks(Uri repoUri) throws IOException {
public List<VersionedRook> getBooks(Uri repoUri, boolean encrypted) throws IOException {
linkedOrThrow();

List<VersionedRook> list = new ArrayList<>();
Expand All @@ -163,7 +163,8 @@ public List<VersionedRook> getBooks(Uri repoUri) throws IOException {
if (metadata instanceof FileMetadata) {
FileMetadata file = (FileMetadata) metadata;

if (BookName.isSupportedFormatFileName(file.getName())) {
if ((!encrypted && BookName.isSupportedFormatFileName(file.getName()))
|| (encrypted && BookName.isEncryptedSupportedFormatFileName(file.getName()))) {
Uri uri = repoUri.buildUpon().appendPath(file.getName()).build();
VersionedRook book = new VersionedRook(
repoId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Uri getUri() {

@Override
public List<VersionedRook> getBooks() throws IOException {
return client.getBooks(repoUri);
return client.getBooks(repoUri, isEncryptionEnabled());
}

@Override
Expand Down

0 comments on commit 529ecf9

Please sign in to comment.