Skip to content

Commit

Permalink
Added ".nomedia" file to backups to avoid media scan (closes #974)
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Apr 22, 2024
1 parent 4590acb commit b3c106c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void exportNotes_nothingToExport() throws IOException {
BackupHelper.exportNotes(backupDir);

assertTrue(backupDir.exists());
assertEquals(0, backupDir.listFiles().size());
assertTrue(backupDir.findFile(".nomedia").exists());
assertEquals(1, backupDir.listFiles().size());
}

@Test
Expand All @@ -101,14 +102,16 @@ public void exportNotes() throws IOException {
BackupHelper.exportNotes(backupDir);

assertTrue(backupDir.exists());
assertEquals(4, backupDir.listFiles().size());
assertTrue(backupDir.findFile(".nomedia").exists());
assertEquals(5, backupDir.listFiles().size());
}

@Test
public void exportNote() {
Note note = createTestNote("test title", "test content", 0);

BackupHelper.exportNote(backupDir, note);

var noteFiles = from(backupDir.listFiles())
.filter(f -> f.getName().matches("\\d{13}.json")).toList().toBlocking().single();
assertEquals(1, noteFiles.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
public final class BackupHelper {

public static void exportNotes(DocumentFileCompat backupDir) {
backupDir.createFile("", ".nomedia");
for (Note note : DbHelper.getInstance(true).getAllNotes(false)) {
exportNote(backupDir, note);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,6 @@ public static File getExternalStoragePublicDir() {
+ File.separator + Constants.EXTERNAL_STORAGE_FOLDER + File.separator);
}

public static File getOrCreateBackupDir(String backupName) {
File backupDir = new File(getOrCreateExternalStoragePublicDir(), backupName);
if (!backupDir.exists() && backupDir.mkdirs()) {
createNoMediaFile(backupDir);
}
return backupDir;
}


private static void createNoMediaFile(File folder) {
try {
boolean created = new File(folder, ".nomedia").createNewFile();
if (!created) {
LogDelegate.w("File .nomedia already existing into " + folder.getAbsolutePath());
}
} catch (IOException e) {
LogDelegate.e("Error creating .nomedia file into backup folder");
}
}


public static File getSharedPreferencesFile(Context mContext) {
File appData = mContext.getFilesDir().getParentFile();
Expand Down

This file was deleted.

0 comments on commit b3c106c

Please sign in to comment.