Remove pi file when last po info is deleted 52/296652/5
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 2 Aug 2023 15:18:08 +0000 (17:18 +0200)
committerDong Sun Lee <ds73.lee@samsung.com>
Fri, 11 Aug 2023 00:27:19 +0000 (00:27 +0000)
Writing 0 bytes to pi file led to a failure, making removal of the last
object impossible.

Change-Id: I0cd1beda44434e44802e491ea825cfa0da8f8ec8

ssflib/src/ssf_storage.cpp

index cf8dcada5ff31c7d21a7811c39fd230441743e7f..ebbbf57199ca9777ad57d4fd9e8e3491d9d04961 100644 (file)
@@ -930,16 +930,24 @@ int delete_po_info(po_info_file* pi_file, const void* objectID,
            - (cp_begin - (uint8_t*)pi_file->po_info);
 
        memcpy(po_del_pos, cp_begin, cp_sz);
+       int retval = 0;
        pi_file->po_num--;
-       int ret = ss_write((uint8_t*)pi_file->po_info, po_info_sz * pi_file->po_num,
-           0, pi_file->filename, &pi_file->cred, SS_OPT_DEFAULT);
-       if (SS_RET_SUCCESS != ret) {
-               MSG("Failed to write po stat to secure storage,ret = %d.", ret);
-               __FREE(pi_file->po_info);
-               return -1;
+       if (pi_file->po_num == 0) {
+               int ret = ss_delete(pi_file->filename, &pi_file->cred, SS_OPT_DEFAULT);
+               if (SS_RET_SUCCESS != ret) {
+                       MSG("Failed to delete pi file,ret = %d.", ret);
+                       retval = -1;
+               }
+       } else {
+               int ret = ss_write((uint8_t*)pi_file->po_info, po_info_sz * pi_file->po_num,
+                       0, pi_file->filename, &pi_file->cred, SS_OPT_DEFAULT);
+               if (SS_RET_SUCCESS != ret) {
+                       MSG("Failed to write po stat to secure storage,ret = %d.", ret);
+                       retval = -1;
+               }
        }
        __FREE(pi_file->po_info);
-       return 0;
+       return retval;
 }
 
 persistent_object_info* find_po_info(po_info_file* pi_file,