Refactor pkg_getsize for reduce dbus call count 46/208546/2
authorSeungha Son <seungha.son@samsung.com>
Wed, 6 Dec 2017 04:57:53 +0000 (13:57 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 26 Jun 2019 04:33:10 +0000 (13:33 +0900)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Iad633c39ed7e8532f55358f8c95d3b885d19a563
(cherry picked from commit 069f2c0cb34f7d36e7794d06ca10412400301359)

src/pkg_getsize.c

index 958ad09a2d4c19075f164f5f27f5d7b8805632dd..805e413f0aac23c6d4d49db71093ed7ba5235a16 100644 (file)
@@ -77,16 +77,26 @@ long long __stat_size(struct stat *s)
 
 static int __get_sdcard_path(char **sdpath)
 {
-       int ret;
+       static int ret = STORAGE_ERROR_NONE;
+       static char sdcard_path[MAX_PATH_LENGTH];
        int storage_id;
+       char *tmp_path;
 
        if (sdpath == NULL)
                return -1;
 
-       ret = storage_get_primary_sdcard(&storage_id, sdpath);
-       if (ret != STORAGE_ERROR_NONE)
+       if (ret == STORAGE_ERROR_NOT_SUPPORTED)
                return -1;
 
+       if (sdcard_path[0] == '\0') {
+               ret = storage_get_primary_sdcard(&storage_id, &tmp_path);
+               if (ret != STORAGE_ERROR_NONE || tmp_path == NULL)
+                       return -1;
+               snprintf(sdcard_path, MAX_PATH_LENGTH, "%s", tmp_path);
+               free(tmp_path);
+       }
+
+       *sdpath = strdup(sdcard_path);
        return 0;
 }