diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilConstants.java deleted file mode 100644 index 76e0e87f1..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/FossilConstants.java +++ /dev/null @@ -1,5 +0,0 @@ -package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; - -public class FossilConstants { - public static String QFILES_DIR = "qFiles"; -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java index 825d864b8..9c2b7fbab 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/FileUtils.java @@ -195,7 +195,8 @@ public class FileUtils { */ public static File getExternalFile(String child) throws IOException { File file = new File(getExternalFilesDir(), child); - if (!file.getParentFile().mkdirs()) { + File dir = file.getParentFile(); + if (!dir.exists() && !dir.mkdirs()) { throw new IOException("Unable to create directory " + file.getParent()); } return file; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/FileUtilsTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/FileUtilsTest.java index a715a958f..e4a4db011 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/FileUtilsTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/FileUtilsTest.java @@ -2,9 +2,14 @@ package nodomain.freeyourgadget.gadgetbridge.test; import org.junit.Test; +import java.io.File; +import java.io.IOException; + import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class FileUtilsTest extends TestBase { @@ -16,4 +21,24 @@ public class FileUtilsTest extends TestBase { tempName = "fo\no::bar"; assertEquals("fo_o__bar", FileUtils.makeValidFileName(tempName)); } + + @Test + public void testExternalFilesDir() throws IOException { + File dir = FileUtils.getExternalFilesDir(); + assertTrue(dir.exists()); + } + + @Test + public void testExternalFile() throws IOException { + File extDir = FileUtils.getExternalFilesDir(); + File dir = FileUtils.getExternalFile("qfiles"); + assertFalse(dir.exists()); + + File file = FileUtils.getExternalFile("qfiles/test"); + assertTrue(file.getParentFile().exists()); + assertFalse(file.exists()); + + File expectedFile = new File(extDir + "/qfiles/test"); + assertEquals(expectedFile.getPath(), file.getPath()); + } }