@@ -1366,6 +1366,10 @@ static void install_btn_event_cb(lv_event_t *e)
13661366 * circle + symbol glyph, so a bad icon never blocks the app from being
13671367 * listed or installed.
13681368 *
1369+ * Cache files include the package version so an updated package does not
1370+ * silently retain an older icon. Corrupt cache files are removed so a
1371+ * later launch can fetch them again.
1372+ *
13691373 * On success, both the returned descriptor and its data pointer are
13701374 * heap-allocated and intentionally never freed - the descriptor is
13711375 * handed straight to a permanent lv_image row widget (which keeps a
@@ -1386,6 +1390,7 @@ nxstore_load_icon(FAR const struct pkg_manifest_s *manifest)
13861390 struct stat st ;
13871391 int fd ;
13881392 ssize_t nread ;
1393+ size_t offset ;
13891394 uint16_t w ;
13901395 uint16_t h ;
13911396 uint16_t stride ;
@@ -1395,8 +1400,9 @@ nxstore_load_icon(FAR const struct pkg_manifest_s *manifest)
13951400 return NULL ;
13961401 }
13971402
1398- snprintf (cache_path , sizeof (cache_path ), PKG_ROOT_DIR "/icons/%s.bin" ,
1399- manifest -> name );
1403+ snprintf (cache_path , sizeof (cache_path ),
1404+ PKG_ROOT_DIR "/icons/%s-%s.bin" ,
1405+ manifest -> name , manifest -> version );
14001406
14011407 if (stat (cache_path , & st ) < 0 )
14021408 {
@@ -1428,12 +1434,36 @@ nxstore_load_icon(FAR const struct pkg_manifest_s *manifest)
14281434 return NULL ;
14291435 }
14301436
1431- nread = read (fd , buf , (size_t )st .st_size );
1437+ offset = 0 ;
1438+ while (offset < (size_t )st .st_size )
1439+ {
1440+ nread = read (fd , buf + offset , (size_t )st .st_size - offset );
1441+ if (nread < 0 )
1442+ {
1443+ if (errno == EINTR )
1444+ {
1445+ continue ;
1446+ }
1447+
1448+ break ;
1449+ }
1450+
1451+ if (nread == 0 )
1452+ {
1453+ break ;
1454+ }
1455+
1456+ offset += nread ;
1457+ }
1458+
14321459 close (fd );
14331460
1434- if (nread != st .st_size || buf [0 ] != LV_IMAGE_HEADER_MAGIC )
1461+ if (offset != (size_t )st .st_size ||
1462+ buf [0 ] != LV_IMAGE_HEADER_MAGIC ||
1463+ buf [1 ] != LV_COLOR_FORMAT_RGB565 )
14351464 {
14361465 pkg_free (buf );
1466+ unlink (cache_path );
14371467 return NULL ;
14381468 }
14391469
@@ -1443,9 +1473,10 @@ nxstore_load_icon(FAR const struct pkg_manifest_s *manifest)
14431473
14441474 if (w == 0 || h == 0 || w > NXSTORE_ICON_MAX_DIM ||
14451475 h > NXSTORE_ICON_MAX_DIM || stride != w * 2 ||
1446- 12 + (size_t )stride * h > (size_t )nread )
1476+ 12 + (size_t )stride * h != (size_t )st . st_size )
14471477 {
14481478 pkg_free (buf );
1479+ unlink (cache_path );
14491480 return NULL ;
14501481 }
14511482
0 commit comments