Refactor pkg_getsize for reduce dbus call count 97/162897/4
authorSeungha Son <seungha.son@samsung.com>
Wed, 6 Dec 2017 04:57:53 +0000 (13:57 +0900)
committerSeungha Son <seungha.son@samsung.com>
Thu, 7 Dec 2017 01:17:18 +0000 (10:17 +0900)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Iad633c39ed7e8532f55358f8c95d3b885d19a563

src/pkg_getsize.c

index 5649ebc244b03e8d9d16286d14b83352a3bd1d9f..7ac5282a7f9ea0b5824e1c3861cfeb03683cd3c8 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_NO_DEVICE)
                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;
 }