Code refactoring
[platform/core/dotnet/launcher.git] / NativeLauncher / util / utils.cc
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <dirent.h>
18 #include <fcntl.h>
19 #include <sys/stat.h>
20 #include <unistd.h>
21 #include <limits.h>
22 #include <strings.h>
23 #include <pkgmgr-info.h>
24 #include <pkgmgr_installer_info.h>
25 #include <sys/smack.h>
26 #include <json/json.h>
27 #include <openssl/sha.h>
28
29 #include <cstdlib>
30 #include <cstring>
31 #include <algorithm>
32 #include <unordered_map>
33 #include <vector>
34 #include <iterator>
35 #include <sstream>
36 #include <map>
37
38 #include "log.h"
39 #include "utils.h"
40 #include "path_manager.h"
41 #include "db_manager.h"
42
43 #define __XSTR(x) #x
44 #define __STR(x) __XSTR(x)
45 static const char* __TAC_DIR = __STR(TAC_DIR);
46 #undef __STR
47 #undef __XSTR
48
49 static bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length)
50 {
51         return static_cast<int>(a.length()) - length >= aOffset &&
52                 static_cast<int>(b.length()) - length >= bOffset &&
53                 std::equal(b.begin() + bOffset, b.begin() + bOffset + length, a.begin() + aOffset,
54                         [](unsigned char a, unsigned char b)
55                         { return std::tolower(a) == std::tolower(b); });
56 }
57
58 bool isManagedAssembly(const std::string& fileName)
59 {
60         return (iCompare(fileName, fileName.size()-4, ".dll", 0, 4) ||
61                         iCompare(fileName, fileName.size()-4, ".exe", 0, 4)) &&
62                         !isNativeImage(fileName);
63 }
64
65 bool isNativeImage(const std::string& fileName)
66 {
67         return iCompare(fileName, fileName.size()-7, ".ni", 0, 3);
68 }
69
70 bool cmdOptionExists(char** begin, char** end, const std::string& option)
71 {
72         return std::find(begin, end, option) != end;
73 }
74
75 std::string readSelfPath()
76 {
77         char buff[PATH_MAX];
78         ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
79         if (len != -1) {
80                 buff[len] = '\0';
81                 return std::string(buff);
82         }
83
84         return "";
85 }
86
87 std::string concatPath(const std::string& path1, const std::string& path2)
88 {
89         std::string path(path1);
90         if (path.back() == PATH_SEPARATOR) {
91                 path.append(path2);
92         } else {
93                 path += PATH_SEPARATOR;
94                 path.append(path2);
95         }
96
97         return path;
98 }
99
100 void splitPath(const std::string& path, std::vector<std::string>& out)
101 {
102         std::istringstream ss(path);
103         std::string token;
104
105         while (std::getline(ss, token, ':')) {
106                 out.push_back(token);
107         }
108 }
109
110 std::string absolutePath(const std::string& path)
111 {
112         std::string absPath;
113         char realPath[PATH_MAX];
114         if (realpath(path.c_str(), realPath) != nullptr && realPath[0] != '\0')
115                 absPath.assign(realPath);
116
117         return absPath;
118 }
119
120 int getRootPath(std::string pkgId, std::string& rootPath)
121 {
122         int ret = 0;
123         char *path = 0;
124         uid_t uid = 0;
125
126         if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
127                 _ERR("Failed to get UID");
128                 return -1;
129         }
130
131         pkgmgrinfo_pkginfo_h handle;
132         if (uid == 0) {
133                 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &handle);
134                 if (ret != PMINFO_R_OK) {
135                         return -1;
136                 }
137         } else {
138                 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &handle);
139                 if (ret != PMINFO_R_OK) {
140                         return -1;
141                 }
142         }
143
144         ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path);
145         if (ret != PMINFO_R_OK) {
146                 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
147                 return -1;
148         }
149         rootPath = path;
150         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
151         return 0;
152 }
153
154 int getExecName(std::string pkgId, std::string& execName)
155 {
156         char *exec = NULL;
157         char *appId = 0;
158
159         pkgmgrinfo_pkginfo_h pkg_handle;
160         int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &pkg_handle);
161         if (ret != PMINFO_R_OK) {
162                 return -1;
163         }
164         ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
165         if (ret != PMINFO_R_OK) {
166                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
167                 return -1;
168         }
169
170         pkgmgrinfo_appinfo_h app_handle;
171         ret = pkgmgrinfo_appinfo_get_appinfo(appId, &app_handle);
172         if (ret != PMINFO_R_OK) {
173                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
174                 return -1;
175         }
176         ret = pkgmgrinfo_appinfo_get_exec(app_handle, &exec);
177         if (ret != PMINFO_R_OK) {
178                 pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
179                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
180                 return -1;
181         }
182         execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
183
184         pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
185         pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
186         return 0;
187 }
188
189 int getMetadataValue(std::string pkgId, std::string metadataKey, std::string& metadataValue)
190 {
191         char *value = NULL;
192         char *appId = 0;
193
194         pkgmgrinfo_pkginfo_h pkg_handle;
195         int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &pkg_handle);
196         if (ret != PMINFO_R_OK) {
197                 return -1;
198         }
199         ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
200         if (ret != PMINFO_R_OK) {
201                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
202                 return -1;
203         }
204
205         pkgmgrinfo_appinfo_h app_handle;
206         ret = pkgmgrinfo_appinfo_get_appinfo(appId, &app_handle);
207         if (ret != PMINFO_R_OK) {
208                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
209                 return -1;
210         }
211         ret = pkgmgrinfo_appinfo_get_metadata_value(app_handle, metadataKey.c_str(), &value);
212         if (ret != PMINFO_R_OK) {
213                 pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
214                 pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
215                 //Does not return error because the metadata key may not exist.
216                 return 0;
217         }
218         metadataValue = std::string(value);
219
220         pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
221         pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
222         return 0;
223 }
224
225 std::string baseName(const std::string& path)
226 {
227         auto pos = path.find_last_of(PATH_SEPARATOR);
228         if (pos != std::string::npos)
229                 return path.substr(0, pos);
230         else
231                 return std::string(".");
232         return path;
233 }
234
235 std::string replaceAll(const std::string &str, const std::string &pattern, const std::string &replace)
236 {
237         std::string result = str;
238         std::string::size_type pos = 0;
239         std::string::size_type offset = 0;
240
241         while ((pos = result.find(pattern, offset)) != std::string::npos) {
242                 result.replace(result.begin() + pos, result.begin() + pos + pattern.size(), replace);
243                 offset = pos + replace.size();
244         }
245
246         return result;
247 }
248
249 bool isFileExist(const std::string& path)
250 {
251         struct stat sb;
252         return stat(path.c_str(), &sb) == 0;
253 }
254
255 uintptr_t getFileSize(const std::string& path)
256 {
257         struct stat sb;
258
259         if (stat(path.c_str(), &sb) == 0) {
260                 return sb.st_size;
261         }
262
263         return 0;
264 }
265
266 std::string stripNiDLL(const std::string& path)
267 {
268         std::string niPath(path);
269         if (path.size() < 5) return niPath;
270         if (!strncasecmp(path.c_str() + path.size() - 4, ".dll", 4))
271                 niPath = path.substr(0, path.size()-4);
272         else if (!strncasecmp(path.c_str() + path.size() - 4, ".exe", 4))
273                 niPath = path.substr(0, path.size()-4);
274
275         if (!strncasecmp(niPath.c_str() + niPath.size() - 3, ".ni", 3))
276                 return niPath.substr(0, niPath.size()-3);
277
278         return niPath;
279 }
280
281 void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList)
282 {
283         std::map<std::string, std::string> assemblyList;
284         std::map<std::string, std::string> tmpList;
285
286         auto reader = [&assemblyList, &tmpList] (const std::string& path, const char* name) {
287                 if (isManagedAssembly(path) || isNativeImage(path)) {
288                         std::string dllName = stripNiDLL(name);
289                         std::pair<std::map<std::string, std::string>::iterator, bool> ret;
290                         ret = tmpList.insert(std::pair<std::string, std::string>(dllName, path));
291                         if (ret.second == false) {
292                                 if (isNativeImage(path))
293                                         tmpList[dllName] = path;
294                         }
295                 }
296         };
297
298         for (auto directory : directories) {
299                 scanFilesInDir(directory.c_str(), reader, 1);
300                 // merge scaned dll list to tpa list.
301                 // if the dll is already exist in the list, that is skipped.
302                 assemblyList.insert(tmpList.begin(), tmpList.end());
303         }
304
305         std::map<std::string, std::string>::iterator it;
306         for (it = assemblyList.begin(); it != assemblyList.end(); it++)
307                 tpaList += it->second + ':';
308
309         if (tpaList.back() == ':')
310                 tpaList.pop_back();
311 }
312
313 void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth)
314 {
315         DIR *dir;
316         struct dirent* entry;
317         bool isDir;
318
319         if (strstr(directory.c_str(), TAC_SYMLINK_SUB_DIR) != NULL)
320                 return;
321
322         dir = opendir(directory.c_str());
323
324         if (dir == nullptr)
325                 return;
326
327         std::vector<std::string> innerDirectories;
328
329         while ((entry = readdir(dir)) != nullptr) {
330                 isDir = false;
331                 std::string path = concatPath(directory, entry->d_name);
332                 switch (entry->d_type) {
333                         case DT_REG: break;
334                         case DT_DIR:
335                                 isDir = true;
336                                 break;
337                         case DT_LNK:
338                         case DT_UNKNOWN:
339                                 struct stat sb;
340                                 if (stat(path.c_str(), &sb) == -1)
341                                         continue;
342
343                                 if (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode))
344                                         break;
345                         default:
346                                 continue;
347                 }
348                 if (!isDir)
349                         reader(path, entry->d_name);
350                 else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
351                         innerDirectories.push_back(path);
352         }
353
354         if (depth != 0)
355                 for (auto& d : innerDirectories)
356                         scanFilesInDir(d.c_str(), reader, depth - 1);
357
358         closedir(dir);
359 }
360
361 void updateAssemblyInfo(const std::string& getPath, const std::string& setPath, bool isSymlink)
362 {
363         char* label = NULL;
364         struct stat info;
365
366         if (isSymlink) {
367                 // change smack label for symbolic link.
368                 if (smack_lgetlabel(getPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
369                         if (smack_lsetlabel(setPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
370                                 fprintf(stderr, "Fail to set smack label\n");
371                         }
372                         free(label);
373                 }
374
375                 // change owner and groups for symbolic link.
376                 if (!stat(getPath.c_str(), &info)) {
377                         if (lchown(setPath.c_str(), info.st_uid, info.st_gid) == -1)
378                                 fprintf(stderr, "Failed to change owner and group name\n");
379                 }
380         } else {
381                 // change smack label
382                 if (smack_getlabel(getPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
383                         if (smack_setlabel(setPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
384                                 fprintf(stderr, "Fail to set smack label\n");
385                         }
386                         free(label);
387                 }
388
389                 // change owner and groups for generated ni file.
390                 if (!stat(getPath.c_str(), &info)) {
391                         if (chown(setPath.c_str(), info.st_uid, info.st_gid) == -1)
392                                 fprintf(stderr, "Failed to change owner and group name\n");
393                 }
394         }
395 }
396
397 static bool setOwnership(const bf::path& path, uid_t uid, gid_t gid) {
398         int fd = open(path.c_str(), O_RDONLY);
399         if (fd < 0) {
400                 _ERR("Can't open directory: %s", path.c_str());
401                 return false;
402         }
403         int ret = fchown(fd, uid, gid);
404         close(fd);
405         if (ret != 0) {
406                 _ERR("Failed to change owner of: %s", path.c_str());
407                 return false;
408         }
409         return true;
410 }
411
412 static bool setDirPermissions(const bf::path& path, bf::perms permissions) {
413         bs::error_code error;
414         bf::permissions(path, permissions, error);
415         if (error) {
416                 _ERR("Failed to set permissions for directory: %s, %s", path.c_str(), error.message().c_str());
417                 return false;
418         }
419         return true;
420 }
421
422 static bool setDirOwnershipAndPermissions(const bf::path& path, bf::perms permissions, uid_t uid, gid_t gid) {
423         if (!setOwnership(path, uid, gid)) {
424                 _ERR("Failed to change owner: %s, (uid: %d, gid: %d)", path.c_str(), uid, gid);
425                 return false;
426         }
427         if (!setDirPermissions(path, permissions)) {
428                 _ERR("Failed to change permission: %s, (%d)", path.c_str(), permissions);
429                 return false;
430         }
431         return true;
432 }
433
434 static bool copyOwnershipAndPermissions(const bf::path& path, const bf::path& path2) {
435         if (!bf::exists(path)) {
436                 _ERR("Failed to copy ownership and permissions from %s to %s", path.c_str(), path2.c_str());
437                 return false;
438         }
439         bf::perms permissions = bf::status(path).permissions();
440         struct stat stats;
441         if (stat(path.c_str(), &stats) != 0) {
442                 return false;
443         }
444         if (!setDirOwnershipAndPermissions(path2, permissions, stats.st_uid, stats.st_gid)) {
445                 _ERR("Failed to copy ownership and permissions from %s to %s", path.c_str(), path2.c_str());
446                 return false;
447         }
448         return true;
449 }
450
451 bool createDir(const bf::path& path) {
452         if (bf::exists(path)) {
453                 return true;
454         }
455         bs::error_code error;
456         bf::create_directories(path, error);
457         if (error) {
458                 _ERR("Failed to create directory: %s", error.message().c_str());
459                 return false;
460         }
461         return true;
462 }
463
464 bool copyDir(const bf::path& path1, const bf::path& path2, FSFlag flags) {
465         try {
466                 // Check whether the function call is valid
467                 if (!bf::exists(path1) || !bf::is_directory(path1)) {
468                         _ERR("Source directory %s does not exist or is not a directory", path1.c_str());
469                         return false;
470                 }
471                 if (!bf::exists(path2)) {
472                         // Create the destination directory
473                         if (!createDir(path2)) {
474                                 _ERR("Unable to create destination directory %s", path2.c_str());
475                                 return false;
476                         }
477                         if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS) {
478                                 copyOwnershipAndPermissions(path1, path2);
479                         }
480                 } else {
481                         if (!(flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE))) {
482                                 _ERR("Destination directory %s already exists", path2.c_str());
483                                 return false;
484                         }
485                         if (flags & (FS_MERGE_OVERWRITE | FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)) {
486                                 copyOwnershipAndPermissions(path1, path2);
487                         }
488                 }
489         } catch (const bf::filesystem_error& error) {
490                 _ERR("Failed to copy directory: %s", error.what());
491                 return false;
492         }
493
494         // Iterate through the source directory
495         for (bf::directory_iterator file(path1); file != bf::directory_iterator(); ++file) {
496                 try {
497                         bf::path current(file->path());
498                         bf::path target = path2 / current.filename();
499                         if (bf::is_symlink(symlink_status(current))) {
500                                 if ((flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE)) && bf::exists(target)) {
501                                         continue;
502                                 }
503                                 bs::error_code error;
504                                 bf::copy_symlink(current, target, error);
505                                 if (error) {
506                                         _ERR("Failed to copy symlink: %s, %s", current.c_str(), error.message().c_str());
507                                         return false;
508                                 }
509                         } else if (bf::is_directory(current)) {
510                                 // Found directory: Recursion
511                                 if (!copyDir(current, target, flags)) {
512                                         return false;
513                                 }
514                         } else {
515                                 if ((flags & FS_MERGE_SKIP) && bf::exists(target)) {
516                                         continue;
517                                 }
518                                 bf::path destination = target;
519                                 if (flags & FS_COMMIT_COPY_FILE) {
520                                         destination = bf::unique_path(target.parent_path() / "%%%%-%%%%-%%%%-%%%%");
521                                 }
522                                 if (flags & FS_MERGE_OVERWRITE) {
523                                         bf::copy_file(current, destination, bf::copy_option::overwrite_if_exists);
524                                 } else {
525                                         bf::copy_file(current, destination);
526                                 }
527                                 if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS) {
528                                         copyOwnershipAndPermissions(current, destination);
529                                 }
530                                 if (flags & FS_COMMIT_COPY_FILE) {
531                                         if (flags & FS_MERGE_OVERWRITE) {
532                                                 bf::remove(target);
533                                         }
534                                         bf::rename(destination, target);
535                                 }
536                         }
537                 } catch (const bf::filesystem_error& error) {
538                         _ERR("Failed to copy directory: %s", error.what());
539                         return false;
540                 }
541         }
542         return true;
543 }
544
545 bool copyFile(const bf::path& path1, const bf::path& path2) {
546         bs::error_code error;
547         if (!bf::exists(path1)) {
548                 return false;
549         }
550         bf::copy_file(path1, path2, bf::copy_option::overwrite_if_exists, error);
551         if (error) {
552                 _ERR("copy file %s due to error [%s]", path1.c_str(), error.message().c_str());
553                 return false;
554         }
555         return true;
556 }
557
558 bool moveFile(const bf::path& path1, const bf::path& path2) {
559         if (!bf::exists(path1) || bf::exists(path2)) {
560                 return false;
561         }
562         bs::error_code error;
563         bf::rename(path1, path2, error);
564         if (error) {
565                 _ERR("Cannot move file: %s. Will copy/remove... with error [%s]", path1.c_str(), error.message().c_str());
566                 bf::copy_file(path1, path2, bf::copy_option::overwrite_if_exists, error);
567                 if (error) {
568                         _ERR("Cannot copy file %s due to error [%s]", path1.c_str(), error.message().c_str());
569                         return false;
570                 }
571                 bf::remove_all(path1, error);
572                 if (error) {
573                         _ERR("Cannot remove old file when coping: %s with error [%s]", path1.c_str(), error.message().c_str());
574                         return false;
575                 }
576         }
577         return true;
578 }
579
580 bool removeFile(const bf::path& path) {
581         if (!bf::exists(path)) {
582                 return true;
583         }
584         bs::error_code error;
585         bf::remove(path, error);
586         if (error) {
587                 _ERR("Cannot remove: %s, %s", path.c_str(), error.message().c_str());
588                 return false;
589         }
590         return true;
591 }
592
593 bool removeAll(const bf::path& path) {
594         if (!exists(path)) {
595                 return true;
596         }
597         bs::error_code error;
598         bf::remove_all(path, error);
599         if (error) {
600                 _ERR("Cannot remove: %s, %s", path.c_str(), error.message().c_str());
601                 return false;
602         }
603         return true;
604 }
605
606 static void SHA256(std::string path, char outputBuffer[65])
607 {
608         FILE *file = fopen(path.c_str(), "rb");
609         if (!file) {
610                 return;
611         }
612
613         unsigned char hash[SHA256_DIGEST_LENGTH];
614         SHA256_CTX sha256;
615         SHA256_Init(&sha256);
616         int bytesRead = 0;
617         const int bufSize = 32768;
618         char *buffer = (char*)malloc(bufSize);
619         if (!buffer) {
620                 fclose(file);
621                 return;
622         }
623
624         while ((bytesRead = fread(buffer, 1, bufSize, file))) {
625                 SHA256_Update(&sha256, buffer, bytesRead);
626         }
627         SHA256_Final(hash, &sha256);
628         for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
629                 sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
630         }
631         outputBuffer[64] = 0;
632
633         fclose(file);
634         free(buffer);
635 }
636
637 std::vector<std::string> depsJsonParser(std::string pkgId, std::string rootPath, std::string execName, std::string tpaList, bool isTool, sqlite3 *tac_db)
638 {
639         std::vector<std::string> parserData;
640         std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
641         std::string depsJsonPath = concatPath(rootPath, depsJsonName);
642         std::string binPath = concatPath(rootPath, "bin");
643         if (bf::exists(depsJsonPath)) {
644                 std::ifstream ifs(depsJsonPath);
645                 Json::CharReaderBuilder reader;
646                 Json::Value root;
647                 std::string error;
648                 if (ifs.is_open()) {
649                         if (!Json::parseFromStream(reader, ifs, &root, &error)) {
650                                 _ERR("Failed to parse of deps.json");
651                                 ifs.close();
652                                 return parserData;
653                         }
654                         const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
655                         const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
656                         for (auto& nuget : nugetPackages.getMemberNames()) {
657                                 if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
658                                         strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) != NULL ||
659                                         strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL ||
660                                         strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) {
661                                         continue;
662                                 } else {
663                                         const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
664                                         if (assemblies != Json::nullValue) {
665                                                 const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
666                                                 bool isDependency = false;
667                                                 for (auto& dependency : dependencies.getMemberNames()) {
668                                                         if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
669                                                                 strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) != NULL) {
670                                                                 continue;
671                                                         } else {
672                                                                 isDependency = true;
673                                                         }
674                                                 }
675                                                 if (!isDependency) {
676                                                         bool isExistTpaAssembly = false;
677                                                         for (auto& assembly : assemblies.getMemberNames()) {
678                                                                 std::string assembly_name = assembly.substr(assembly.rfind('/') + 1);
679                                                                 if (strstr(replaceAll(tpaList, ".ni.dll", ".dll").c_str(), assembly_name.c_str()) != NULL) {
680                                                                         isExistTpaAssembly = true;
681                                                                         break;
682                                                                 }
683                                                         }
684                                                         if (!isExistTpaAssembly) {
685                                                                 _INFO("Nuget : %s", nuget.c_str());
686                                                                 if (isTool) {
687                                                                         if (tac_db) {
688                                                                                 std::string name = nuget.substr(0, nuget.find('/'));
689                                                                                 std::string version = nuget.substr(nuget.rfind('/') + 1);
690                                                                                 std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
691                                                                                 "VALUES ('" + pkgId + "', '" + nuget + "', '" + name + "', '" + version + "');";
692                                                                                 dbInsert(tac_db, TAC_APP_LIST_RESTORE_DB, sql);
693                                                                                 parserData.push_back(concatPath(__TAC_DIR, name));
694                                                                         } else {
695                                                                                 std::string nugetPath = concatPath(__TAC_DIR, nuget);
696                                                                                 if (bf::exists(nugetPath)) {
697                                                                                         for (auto& assembly : assemblies.getMemberNames()) {
698                                                                                                 std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
699                                                                                                 std::string originPath = concatPath(nugetPath, assemblyName);
700                                                                                                 if (bf::exists(originPath)) {
701                                                                                                         parserData.push_back(originPath);
702                                                                                                 }
703                                                                                         }
704                                                                                 }
705                                                                         }
706                                                                 } else {
707                                                                         for (auto& assembly : assemblies.getMemberNames()) {
708                                                                                 std::string assembly_name = assembly.substr(assembly.rfind('/') + 1);
709                                                                                 char buffer[65] = {0};
710                                                                                 SHA256(concatPath(binPath, assembly_name), buffer);
711                                                                                 parserData.push_back(nuget + "/" + assembly_name + "/" + buffer);
712                                                                                 _INFO("Assembly / SHA256 : %s / %s", assembly_name.c_str(), buffer);
713                                                                         }
714                                                                 }
715                                                         }
716                                                 }
717                                         }
718                                 }
719                         }
720                         ifs.close();
721                 }
722         }
723         return parserData;
724 }