Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,9 @@ internal class UpdateTask(
val body = fr.v.second
val serialized = String(body.bytes(), StandardCharsets.UTF_8)
try {
val releaseConfig = ReleaseConfig.deSerialize(serialized).getOrThrow()
var releaseConfig = ReleaseConfig.deSerialize(serialized).getOrThrow()
trackReleaseConfigFetchResult(fr, startTime)
releaseConfig = transformReleaseConfig(releaseConfig)
releaseConfig
} catch (e: Exception) {
Log.e(
Expand All @@ -398,6 +399,27 @@ internal class UpdateTask(
}
}

private fun transformReleaseConfig(releaseConfig: ReleaseConfig): ReleaseConfig {
val localResources = localReleaseConfig?.resources.orEmpty()
val localPackageImportantRes = localReleaseConfig?.pkg?.important.orEmpty()
val newResources = releaseConfig.resources.filter { it !in localResources && it !in localPackageImportantRes }

if (newResources.isEmpty()) return releaseConfig

val updatedResources = ReleaseConfig.ResourceManifest(releaseConfig.resources - newResources.toSet())

val updatedPackage = releaseConfig.pkg.copy(
important = releaseConfig.pkg.important + newResources
)

Log.d(TAG, "Transformed release config with new resources: $newResources")

return releaseConfig.copy(
pkg = updatedPackage,
resources = updatedResources
)
}

fun copyTempPkg(): ReleaseConfig.PackageManifest? {
readPersistentState(StateKey.SAVED_PACKAGE_UPDATE)?.let {
Log.d(TAG, "Found saved pkg $it.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ @interface AJPApplicationManager() {
@property (nonatomic, strong) AJPFileUtil* fileUtil;
@property (nonatomic, strong) AJPRemoteFileUtil* remoteFileUtil;

// Helper method to check if a resource already exists in package important splits
- (BOOL)isResourceExistingInPackageImportantSplits:(AJPResource *)resource package:(AJPApplicationPackage *)package;

@end

@implementation AJPApplicationManager
Expand Down Expand Up @@ -675,7 +678,8 @@ - (void)startDownload {
self.resourceDownloadStatus = DOWNLOADING;
[self fetchReleaseConfigWithCompletionHandler:^(AJPApplicationManifest* manifest,NSError* error) {
if (error==nil && manifest != nil) {
self.downloadedApplicationManifest = manifest;
AJPApplicationManifest *transformedManifest = [self transformDownloadedManifest:manifest];
self.downloadedApplicationManifest = transformedManifest ?: manifest;
self.releaseConfigDownloadStatus = COMPLETED;
[self cleanUpUnwantedFiles];
[self updateConfig:manifest.config];
Expand Down Expand Up @@ -950,6 +954,75 @@ - (void)fetchReleaseConfigWithCompletionHandler:(AJPReleaseConfigCompletionHandl
[manifestDataTask resume];
}

- (BOOL)isResourceExistingInPackageImportantSplits:(AJPResource *)resource package:(AJPApplicationPackage *)package {
if (!resource || !package) {
return NO;
}

NSArray<AJPResource *> *allImportantSplits = [package allImportantSplits];
for (AJPResource *existingResource in allImportantSplits) {
if ([existingResource.filePath isEqualToString:resource.filePath]) {
return YES;
}
}

return NO;
}

- (AJPApplicationManifest *)transformDownloadedManifest:(AJPApplicationManifest *)downloadedManifest {
if (!downloadedManifest) {
return nil;
}

AJPApplicationManifest *localManifest = [self getCurrentApplicationManifest];

AJPApplicationPackage *transformedPackage = [[AJPApplicationPackage alloc] init];
transformedPackage.version = downloadedManifest.package.version;
transformedPackage.name = downloadedManifest.package.name;
transformedPackage.important = [downloadedManifest.package.important mutableCopy];
Copy link
Copy Markdown
Contributor

@balaganesh-juspay balaganesh-juspay Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuvrajjsingh0 Can you set index & properties as well in transformedPackage?

transformedPackage.lazy = [downloadedManifest.package.lazy mutableCopy];

AJPApplicationResources *transformedResources = [[AJPApplicationResources alloc] init];
transformedResources.resources = [downloadedManifest.resources.resources mutableCopy];

NSDictionary<NSString*, AJPResource*> *localResources = localManifest.resources.resources;
NSMutableDictionary<NSString*, AJPResource*> *newResources = [transformedResources.resources mutableCopy];

NSMutableArray<AJPResource*> *resourcesToMoveToImportant = [NSMutableArray array];

for (NSString *resourceKey in newResources) {
AJPResource *newResource = newResources[resourceKey];
AJPResource *localResource = localResources[resourceKey];

// Check if resource is new or updated AND not already in local package important splits
if ((!localResource || ![newResource.url.absoluteString isEqualToString:localResource.url.absoluteString]) &&
![self isResourceExistingInPackageImportantSplits:newResource package:localManifest.package]) {
[resourcesToMoveToImportant addObject:newResource];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resource will always go to package in all the subsequent runs. We should decide if a resource is new after checking for that resource in package also.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with android as well.

Copy link
Copy Markdown
Contributor Author

@yuvrajjsingh0 yuvrajjsingh0 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added a check to see if we have it in pkg important as well before moving

}
}

if (resourcesToMoveToImportant.count > 0) {
NSMutableArray<AJPResource*> *updatedImportantSplits = [transformedPackage.important mutableCopy];
[updatedImportantSplits addObjectsFromArray:resourcesToMoveToImportant];
transformedPackage.important = updatedImportantSplits;

for (AJPResource *resource in resourcesToMoveToImportant) {
[newResources removeObjectForKey:resource.filePath];
}
transformedResources.resources = newResources;

[self.tracker trackInfo:@"manifest_transformation"
value:[@{@"resources_moved_to_important": @(resourcesToMoveToImportant.count)} mutableCopy]];
}

AJPApplicationManifest *transformedManifest = [[AJPApplicationManifest alloc]
initWithPackage:transformedPackage
config:downloadedManifest.config
resources:transformedResources];

return transformedManifest;
}

# pragma mark - Config

- (AJPApplicationConfig *)readApplicationConfig {
Expand Down
Loading