4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>
\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
12 * http://www.apache.org/licenses/LICENSE-2.0
\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
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
26 #include <sys/time.h>
\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
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
39 da_result_t install_content(stage_info *stage)
\r
41 da_result_t ret = DA_RESULT_OK;
\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
48 DA_LOG_FUNC_START(InstallManager);
\r
51 return DA_ERR_INVALID_ARGUMENT;
\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
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
64 ret = check_enough_storage(stage);
\r
65 if (ret != DA_RESULT_OK)
\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
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
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
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
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
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
106 if (!in_file_name || !out_will_install_path)
\r
107 return DA_ERR_INVALID_ARGUMENT;
\r
109 *out_will_install_path = DA_NULL;
\r
111 if (in_install_path_client_wants) {
\r
112 install_dir = in_install_path_client_wants;
\r
114 default_install_dir = PI_get_default_install_dir();
\r
115 if (default_install_dir)
\r
116 install_dir = default_install_dir;
\r
118 return DA_ERR_FAIL_TO_INSTALL_FILE;
\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
127 final_path = get_full_path_avoided_duplication(install_dir, pure_file_name, extension);
\r
129 ret = DA_ERR_FAIL_TO_INSTALL_FILE;
\r
131 *out_will_install_path = final_path;
\r
133 DA_LOG(InstallManager,"Final install path[%s]", *out_will_install_path);
\r