Revert manifest to default one
[profile/ivi/download-provider.git] / src / agent / download-agent-installation.c
1 /*\r
2  * Download Agent\r
3  *\r
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
5  *\r
6  * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>\r
7  *\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *     http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  *\r
20  * @file                download-agent-installation.c\r
21  * @brief               Functions for Content Installation\r
22  * @author              Keunsoon Lee(keunsoon.lee@samsung.com)\r
23  * @author              Jungki Kwak(jungki.kwak@samsung.com)\r
24  ***/\r
25 \r
26 #include <sys/time.h>\r
27 #include <unistd.h>\r
28 \r
29 #include "download-agent-client-mgr.h"\r
30 #include "download-agent-dl-info-util.h"\r
31 #include "download-agent-http-mgr.h"\r
32 #include "download-agent-http-misc.h"\r
33 #include "download-agent-installation.h"\r
34 #include "download-agent-file.h"\r
35 #include "download-agent-plugin-install.h"\r
36 \r
37 da_result_t _extract_file_path_which_will_be_installed(char *in_file_name, char *in_extension, char *in_install_path_client_wants, char **out_will_install_path);\r
38 \r
39 da_result_t install_content(stage_info *stage)\r
40 {\r
41         da_result_t ret = DA_RESULT_OK;\r
42 \r
43         file_info *file_storage = DA_NULL;\r
44         char *temp_saved_file_path = DA_NULL;\r
45         char *install_file_path = DA_NULL;\r
46         unsigned int start_time = 0;\r
47 \r
48         DA_LOG_FUNC_START(InstallManager);\r
49 \r
50         if (!stage)\r
51                 return DA_ERR_INVALID_ARGUMENT;\r
52 \r
53         file_storage = GET_STAGE_CONTENT_STORE_INFO(stage);\r
54         if (!file_storage) {\r
55                 DA_LOG_ERR(InstallManager,"file_storage structure is NULL");\r
56                 ret = DA_ERR_INVALID_ARGUMENT;\r
57                 goto ERR;\r
58         }\r
59 \r
60         temp_saved_file_path =\r
61                         GET_CONTENT_STORE_TMP_FILE_NAME(file_storage);\r
62         DA_LOG(InstallManager,"Source path[%s]",temp_saved_file_path);\r
63 \r
64         ret = check_enough_storage(stage);\r
65         if (ret != DA_RESULT_OK)\r
66                 goto ERR;\r
67 \r
68         ret = _extract_file_path_which_will_be_installed(\r
69                         GET_CONTENT_STORE_PURE_FILE_NAME(file_storage),\r
70                         GET_CONTENT_STORE_EXTENSION(file_storage),\r
71                         GET_DL_USER_INSTALL_PATH(GET_STAGE_DL_ID(stage)),\r
72                         &install_file_path);\r
73         if (ret != DA_RESULT_OK)\r
74                 goto ERR;\r
75 \r
76         DA_LOG(InstallManager,"Installing path [%s]", install_file_path);\r
77         DA_LOG(InstallManager,"Move start time : [%ld]",start_time=time(NULL));\r
78         ret = move_file(temp_saved_file_path, install_file_path);\r
79         if (ret != DA_RESULT_OK)\r
80                 goto ERR;\r
81 \r
82         if (GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage))\r
83                 free(GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage));\r
84         GET_CONTENT_STORE_ACTUAL_FILE_NAME(file_storage) = install_file_path;\r
85         install_file_path = DA_NULL;\r
86 \r
87 \r
88 ERR:\r
89         if (ret != DA_RESULT_OK) {\r
90                 remove_file(GET_CONTENT_STORE_TMP_FILE_NAME(file_storage));\r
91                 remove_file(install_file_path);\r
92         } else {\r
93         }\r
94         return ret;\r
95 }\r
96 \r
97 da_result_t _extract_file_path_which_will_be_installed(char *in_file_name, char *in_extension, char *in_install_path_client_wants, char **out_will_install_path)\r
98 {\r
99         da_result_t ret = DA_RESULT_OK;\r
100         char *install_dir = NULL;\r
101         char *default_install_dir = NULL;\r
102         char *final_path = NULL;\r
103         char *pure_file_name = in_file_name;\r
104         char *extension = in_extension;\r
105 \r
106         if (!in_file_name || !out_will_install_path)\r
107                 return DA_ERR_INVALID_ARGUMENT;\r
108 \r
109         *out_will_install_path = DA_NULL;\r
110 \r
111         if (in_install_path_client_wants) {\r
112                 install_dir = in_install_path_client_wants;\r
113         } else {\r
114                 default_install_dir = PI_get_default_install_dir();\r
115                 if (default_install_dir)\r
116                         install_dir = default_install_dir;\r
117                 else\r
118                         return DA_ERR_FAIL_TO_INSTALL_FILE;\r
119         }\r
120 \r
121         if (DA_FALSE == is_dir_exist(install_dir)) {\r
122                 ret = create_dir(install_dir);\r
123                 if (ret != DA_RESULT_OK)\r
124                         return DA_ERR_FAIL_TO_INSTALL_FILE;\r
125         }\r
126 \r
127         final_path = get_full_path_avoided_duplication(install_dir, pure_file_name, extension);\r
128         if (!final_path)\r
129                 ret = DA_ERR_FAIL_TO_INSTALL_FILE;\r
130 \r
131         *out_will_install_path = final_path;\r
132 \r
133         DA_LOG(InstallManager,"Final install path[%s]", *out_will_install_path);\r
134 \r
135         return ret;\r
136 }\r