Skip to content

Commit ef0aeb6

Browse files
committed
Merge branch 'master' into fix_dynamic_module_support_bug
2 parents 0c1db7c + 3c323f2 commit ef0aeb6

File tree

5 files changed

+1342
-1512
lines changed

5 files changed

+1342
-1512
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ci/ChangedModulesTask.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ abstract class ChangedModulesTask : DefaultTask() {
3333
AffectedProjectFinder(project, changedGitPaths.toSet(), listOf()).find().map { it.path }
3434
.toSet()
3535

36-
val result = mutableMapOf<String, MutableSet<String>>()
36+
val result = project.rootProject.subprojects.associate {
37+
it.path to mutableSetOf<String>()
38+
}
3739
project.rootProject.subprojects.forEach { p ->
3840
p.configurations.forEach { c ->
3941
c.dependencies.filterIsInstance<ProjectDependency>().forEach {
40-
result.getOrPut(it.dependencyProject.path) { mutableSetOf() }.add(p.path)
42+
result[it.dependencyProject.path]?.add(p.path)
4143
}
4244
}
4345
}

firebase-ml-modeldownloader/src/main/java/com/google/firebase/ml/modeldownloader/internal/ModelFileManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public static ModelFileManager getInstance(@NonNull FirebaseApp app) {
7070
void deleteNonLatestCustomModels() throws FirebaseMlException {
7171
File root = getDirImpl("");
7272

73-
boolean ret = true;
7473
if (root.isDirectory()) {
7574
for (File f : root.listFiles()) {
7675
// for each custom model sub directory - extract customModelName and clean up old models.
@@ -212,7 +211,7 @@ public synchronized File moveModelToDestinationFolder(
212211
public synchronized void deleteOldModels(
213212
@NonNull String modelName, @NonNull String latestModelFilePath) {
214213
File modelFolder = getModelDirUnsafe(modelName);
215-
if (!modelFolder.exists()) {
214+
if (!modelFolder.exists() || latestModelFilePath.isEmpty()) {
216215
return;
217216
}
218217

firebase-ml-modeldownloader/src/test/java/com/google/firebase/ml/modeldownloader/internal/ModelFileManagerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,29 @@ public void deleteNonLatestCustomModels_fileToDelete()
188188
assertTrue(new File(modelDestinationFolder + "/1").exists());
189189
}
190190

191+
@Test
192+
public void deleteNonLatestCustomModels_whenModelOnDiskButNotInPreferences()
193+
throws FirebaseMlException, IOException {
194+
String modelDestinationFolder2 = setUpTestingFiles(app, MODEL_NAME_2);
195+
196+
// Was just downloaded
197+
MoveFileToDestination(modelDestinationFolder, testModelFile, CUSTOM_MODEL_NO_FILE, 0);
198+
// Was downloaded previously via FirebaseModelManager
199+
MoveFileToDestination(modelDestinationFolder2, testModelFile2, CUSTOM_MODEL_NO_FILE_2, 0);
200+
201+
sharedPreferencesUtil.setLoadedCustomModelDetails(
202+
new CustomModel(MODEL_NAME, MODEL_HASH, 100, 0, modelDestinationFolder + "/0"));
203+
204+
// Download in progress, hence file path is not present
205+
sharedPreferencesUtil.setLoadedCustomModelDetails(
206+
new CustomModel(MODEL_NAME_2, MODEL_HASH_2, 100, 0));
207+
208+
fileManager.deleteNonLatestCustomModels();
209+
210+
assertTrue(new File(modelDestinationFolder + "/0").exists());
211+
assertTrue(new File(modelDestinationFolder2 + "/0").exists());
212+
}
213+
191214
@Test
192215
public void deleteNonLatestCustomModels_noFileToDelete()
193216
throws FirebaseMlException, FileNotFoundException {

0 commit comments

Comments
 (0)