Check library extensions more accurately
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / tac_common.cc
1 /*
2  * Copyright (c) 2019 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 <fstream>
18 #include <json/json.h>
19 #include <pkgmgr-info.h>
20 #include <pkgmgr_installer_info.h>
21
22 #include "log.h"
23 #include "utils.h"
24 #include "tac_common.h"
25 #include "db_manager.h"
26
27 #ifdef  LOG_TAG
28 #undef  LOG_TAG
29 #endif
30 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
31
32 #define __XSTR(x) #x
33 #define __STR(x) __XSTR(x)
34 static const char* __DOTNET_DIR = __STR(DOTNET_DIR);
35 static const char* __READ_ONLY_APP_UPDATE_DIR = __STR(READ_ONLY_APP_UPDATE_DIR);
36 #undef __STR
37 #undef __XSTR
38
39 static sqlite3 *tac_db = NULL;
40 static sqlite3 *tlc_db = NULL;
41 std::vector<std::string> restore_nuget;
42 std::vector<std::string> restore_library;
43
44 static void cleanupDirectory()
45 {
46         std::vector<std::string> removeNuget;
47         try {
48                 for (auto& nuget : bf::recursive_directory_iterator(__DOTNET_DIR)) {
49                         std::string nugetPath = nuget.path().string();
50                         if (!bf::is_directory(nugetPath) ||
51                                 nugetPath.find(TLC_LIBRARIES_DIR) != std::string::npos ||
52                                 nugetPath.find(__READ_ONLY_APP_UPDATE_DIR) != std::string::npos) {
53                                 continue;
54                         }
55
56                         bool isExist = false;
57                         for (auto& restore : restore_nuget) {
58                                 if (nugetPath == restore || nugetPath == getBaseName(restore)) {
59                                         isExist = true;
60                                         break;
61                                 }
62                         }
63                         if (!isExist) {
64                                 removeNuget.push_back(nugetPath);
65                         }
66                 }
67
68                 for (auto& rm : removeNuget) {
69                         if (!removeAll(rm)) {
70                                 _SERR("Failed to remove of %s", rm.c_str());
71                         }
72                 }
73                 removeNuget.clear();
74         } catch (const bf::filesystem_error& error) {
75                 _SERR("Failed to recursive directory: %s", error.what());
76                 return;
77         }
78 }
79
80 // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
81 static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
82 {
83         char *pkgId = NULL;
84         char *root = NULL;
85         char *exec = NULL;
86
87         int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
88         if (ret != PMINFO_R_OK) {
89                 _SERR("Failed to get pkgid");
90                 return -1;
91         }
92
93         ret = pkgmgrinfo_appinfo_get_root_path(handle, &root);
94         if (ret != PMINFO_R_OK) {
95                 _SERR("Failed to get root path");
96                 return -1;
97         }
98         std::string rootPath = std::string(root);
99
100         ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
101         if (ret != PMINFO_R_OK) {
102                 _SERR("Failed to get exec name");
103                 return -1;
104         }
105         std::string execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
106
107         enableTACPackage(std::string(pkgId));
108
109         std::vector<std::string> parserData;
110         std::string binDir = concatPath(rootPath, "bin");
111         std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
112         for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
113                 std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
114                 std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
115                 if (exist(tacDir) && exist(concatPath(tacDir, assemblyName))) {
116                         parserData.push_back(nugetPackage);
117                 }
118         }
119         std::sort(parserData.begin(), parserData.end());
120         parserData.erase(unique(parserData.begin(), parserData.end()), parserData.end());
121
122         for (auto& nuget : parserData) {
123                 if (tac_db) {
124                         std::string name = nuget.substr(0, nuget.find('/'));
125                         std::string version = nuget.substr(nuget.rfind('/') + 1);
126                         char *sql = sqlite3_mprintf(
127                                 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
128                                 "VALUES (%Q, %Q, %Q, %Q);",     pkgId, nuget.c_str(), name.c_str(), version.c_str());
129                         insertDB(tac_db, sql);
130                         restore_nuget.push_back(concatPath(__DOTNET_DIR, nuget));
131                         sqlite3_free(sql);
132                 }
133         }
134         parserData.clear();
135
136         return 0;
137 }
138
139 tac_error_e tac_restoreDB()
140 {
141         if (!removeFile(TAC_APP_LIST_RESTORE_DB)) {
142                 _SERR("Failed to remove of %s", TAC_APP_LIST_RESTORE_DB);
143                 return TAC_ERROR_UNKNOWN;
144         }
145
146         std::string dbRestoreJournal = TAC_APP_LIST_RESTORE_DB + std::string("-journal");
147         if (!removeFile(dbRestoreJournal)) {
148                 _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
149                 return TAC_ERROR_UNKNOWN;
150         }
151
152         tac_db = createDB(TAC_APP_LIST_RESTORE_DB, CREATE_TAC_DB_TABLE);
153         if (!tac_db) {
154                 _SERR("Sqlite create error");
155                 return TAC_ERROR_UNKNOWN;
156         }
157         sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
158
159         pkgmgrinfo_appinfo_metadata_filter_h handle;
160         int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
161         if (ret != PMINFO_R_OK) {
162                 return TAC_ERROR_UNKNOWN;
163         }
164
165         ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
166         if (ret != PMINFO_R_OK) {
167                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
168                 return TAC_ERROR_UNKNOWN;
169         }
170
171         ret = pkgmgrMDFilterForeach(handle, tac_restoreDBCb, NULL);
172         if (ret != 0) {
173                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
174                 return TAC_ERROR_UNKNOWN;
175         }
176
177         pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
178
179         if (tac_db) {
180                 closeDB(tac_db);
181                 tac_db = NULL;
182         }
183
184         if (!copyFile(TAC_APP_LIST_RESTORE_DB, TAC_APP_LIST_DB)) {
185                 _SERR("Failed to copy of %s", TAC_APP_LIST_DB);
186                 return TAC_ERROR_UNKNOWN;
187         }
188         if (!removeFile(TAC_APP_LIST_RESTORE_DB)) {
189                 _SERR("Failed to remove of %s", TAC_APP_LIST_RESTORE_DB);
190                 return TAC_ERROR_UNKNOWN;
191         }
192
193         std::string dbJournal = TAC_APP_LIST_DB + std::string("-journal");
194         if (!copyFile(dbRestoreJournal, dbJournal)) {
195                 _SERR("Failed to copy of %s", dbJournal.c_str());
196                 return TAC_ERROR_UNKNOWN;
197         }
198         if (!removeFile(dbRestoreJournal)) {
199                 _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
200                 return TAC_ERROR_UNKNOWN;
201         }
202
203         cleanupDirectory();
204
205         return TAC_ERROR_NONE;
206 }
207
208 tac_error_e disableTACPackage(const std::string& pkgId)
209 {
210         std::string rootPath = getRootPath(pkgId);
211         if (rootPath.empty()) {
212                 _SERR("Failed to get root path from [%s]", pkgId.c_str());
213                 return TAC_ERROR_INVALID_PACKAGE;
214         }
215
216         std::string binDir = concatPath(rootPath, "bin");
217         std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
218         std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
219         if (exist(tacDir)) {
220                 try {
221                         for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
222                                 std::string symPath = symlinkAssembly.path().string();
223                                 std::string fileName = symlinkAssembly.path().filename().string();
224                                 if (isSymlinkFile(symPath)) {
225                                         std::string originPath = bf::read_symlink(symPath).string();
226                                         if (!isNativeImage(symPath)) {
227                                                 std::string dllPath = concatPath(binDir, fileName);
228                                                 if (!copyFile(originPath, dllPath)) {
229                                                         _SERR("Failed to copy of %s", dllPath.c_str());
230                                                         return TAC_ERROR_UNKNOWN;
231                                                 }
232                                                 copySmackAndOwnership(binDir.c_str(), concatPath(binDir, fileName).c_str());
233                                         } else {
234                                                 std::string niPath = concatPath(binNIDir, fileName);
235                                                 if (!copyFile(originPath, niPath)) {
236                                                         _SERR("Failed to copy of %s", niPath.c_str());
237                                                         return TAC_ERROR_UNKNOWN;
238                                                 }
239                                                 copySmackAndOwnership(binDir.c_str(), niPath.c_str());
240                                         }
241                                 }
242                         }
243                         if (!removeAll(tacDir)) {
244                                 _SERR("Failed to remove of %s", tacDir.c_str());
245                                 return TAC_ERROR_UNKNOWN;
246                         }
247                 } catch (const bf::filesystem_error& error) {
248                         _SERR("Failed to recursive directory: %s", error.what());
249                         return TAC_ERROR_UNKNOWN;
250                 }
251         }
252         return TAC_ERROR_NONE;
253 }
254
255 tac_error_e enableTACPackage(const std::string& pkgId)
256 {
257         std::string rootPath = getRootPath(pkgId);
258         if (rootPath.empty()) {
259                 _SERR("Failed to get root path from [%s]", pkgId.c_str());
260                 return TAC_ERROR_INVALID_PACKAGE;
261         }
262
263         std::string binDir = concatPath(rootPath, "bin");
264         if (exist(concatPath(binDir, PRE_COMPILED_PACKAGE_FILE))) {
265                 _INFO("The %s is a Pre-Compiled package. So, skip the TAC", pkgId.c_str());
266                 return TAC_ERROR_NONE;
267         }
268
269         std::string execName = getExecName(pkgId);
270         if (execName.empty()) {
271                 _SERR("Failed to get exec name from [%s]", pkgId.c_str());
272                 return TAC_ERROR_INVALID_PACKAGE;
273         }
274
275         std::string metaValue = getMetadataValue(pkgId, TAC_METADATA_KEY);
276         if (metaValue.empty()) {
277                 _SERR("Failed to get metadata from [%s]", pkgId.c_str());
278                 return TAC_ERROR_INVALID_PACKAGE;
279         }
280
281         if (!strcmp(metaValue.c_str(), METADATA_VALUE_TRUE)) {
282                 std::string binDir = concatPath(rootPath, "bin");
283                 std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
284                 std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
285                 if (!exist(tacDir)) {
286                         if (!createDir(tacDir)) {
287                                 _SERR("Cannot create directory: %s", tacDir.c_str());
288                                 return TAC_ERROR_UNKNOWN;
289                         }
290                         copySmackAndOwnership(binDir.c_str(), tacDir.c_str());
291
292                         std::vector<std::string> enableNuget;
293                         for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
294                                 std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
295                                 std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
296                                 std::string nugetPath = concatPath(__DOTNET_DIR, nugetPackage);
297                                 if (exist(nugetPath)) {
298                                         std::string originPath = concatPath(nugetPath, assemblyName);
299                                         if (exist(originPath)) {
300                                                 enableNuget.push_back(originPath);
301                                         }
302                                 }
303                         }
304
305                         bs::error_code error;
306                         for (auto& originPath : enableNuget) {
307                                 if (exist(originPath)) {
308                                         std::string fileName = originPath.substr(originPath.rfind('/') + 1);
309                                         std::string NIFileName = changeExtension(fileName, "dll", "ni.dll");
310                                         if (exist(binNIDir)) {
311                                                 std::string originNIPath = changeExtension(originPath, "dll", "ni.dll");
312                                                 if (exist(originNIPath)) {
313                                                         bf::create_symlink(originNIPath, concatPath(tacDir, NIFileName), error);
314                                                         if (error) {
315                                                                 _SERR("Failed to create symlink %s file", concatPath(tacDir, NIFileName).c_str());
316                                                                 return TAC_ERROR_UNKNOWN;
317                                                         }
318                                                         _SOUT("%s symbolic link file generated successfully.", concatPath(tacDir, NIFileName).c_str());
319                                                         copySmackAndOwnership(tacDir.c_str(), concatPath(tacDir, NIFileName).c_str(), true);
320
321                                                         if (!removeFile(concatPath(binNIDir, NIFileName))) {
322                                                                 _SERR("Failed to remove of %s", concatPath(binNIDir, NIFileName).c_str());
323                                                                 return TAC_ERROR_UNKNOWN;
324                                                         }
325                                                 }
326                                         }
327                                         bf::create_symlink(originPath, concatPath(tacDir, fileName), error);
328                                         if (error) {
329                                                 _SERR("Failed to create symlink %s file", concatPath(tacDir, fileName).c_str());
330                                                 return TAC_ERROR_UNKNOWN;
331                                         }
332                                         _SOUT("%s symbolic link file generated successfully.", concatPath(tacDir, fileName).c_str());
333                                         copySmackAndOwnership(tacDir.c_str(), concatPath(tacDir, fileName).c_str(), true);
334
335                                         if (!removeFile(concatPath(binDir, fileName))) {
336                                                 _SERR("Failed to remove of %s", concatPath(binDir, fileName).c_str());
337                                                 return TAC_ERROR_UNKNOWN;
338                                         }
339                                 }
340                         }
341                         if (enableNuget.empty()) {
342                                 if (!removeAll(tacDir)) {
343                                         _SERR("Failed to remove of %s", tacDir.c_str());
344                                 }
345                         }
346                         enableNuget.clear();
347                 }
348         } else {
349                 _SERR("The metadata key is missing or the metadata value is false of [%s]", pkgId.c_str());
350         }
351         return TAC_ERROR_NONE;
352 }
353
354 //Parser the .deps.json file to get nuget information.
355 std::vector<std::string> depsJsonParser(const std::string& rootPath, const std::string& execName)
356 {
357         std::vector<std::string> parserData;
358         std::string depsJsonName = changeExtension(execName, "dll", "deps.json");
359         std::string depsJsonPath = concatPath(rootPath, depsJsonName);
360         try {
361                 if (exist(depsJsonPath)) {
362                         std::ifstream ifs(depsJsonPath);
363                         Json::CharReaderBuilder reader;
364                         Json::Value root;
365                         std::string error;
366                         if (ifs.is_open()) {
367                                 if (!Json::parseFromStream(reader, ifs, &root, &error)) {
368                                         _ERR("Failed to parse of deps.json");
369                                         ifs.close();
370                                         return parserData;
371                                 }
372                                 const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
373                                 const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
374                                 std::vector<std::string> appDependencies;
375                                 for (auto& nuget : nugetPackages.getMemberNames()) {
376                                         if (strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL ||
377                                                 strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) {
378                                                 const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
379                                                 if (assemblies != Json::nullValue) {
380                                                         const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
381                                                         for (auto& dependency : dependencies.getMemberNames()) {
382                                                                 appDependencies.push_back(dependency);
383                                                         }
384                                                 }
385                                         }
386                                 }
387                                 for (auto& nuget : nugetPackages.getMemberNames()) {
388                                         //Skip the nuget package related to Tizen
389                                         if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
390                                                 strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) == NULL &&
391                                                 strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) == NULL &&
392                                                 strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) == NULL) {
393                                                 const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
394                                                 if (assemblies != Json::nullValue) {
395                                                         const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"];
396                                                         bool hasDependency = false;
397                                                         for (auto& dependency : dependencies.getMemberNames()) {
398                                                                 //Skip the nugget package that is dependent on another nuget package
399                                                                 if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
400                                                                         strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) {
401                                                                         hasDependency = true;
402                                                                         for (auto& ad : appDependencies) {
403                                                                                 if (!strcmp(ad.c_str(), dependency.c_str())) {
404                                                                                         hasDependency = true;
405                                                                                         break;
406                                                                                 } else {
407                                                                                         hasDependency = false;
408                                                                                 }
409                                                                         }
410                                                                         if (hasDependency) break;
411                                                                 }
412                                                         }
413                                                         if (!hasDependency) {
414                                                                 // handle assembly even though that is included in the TPA.
415                                                                 for (auto& assembly : assemblies.getMemberNames()) {
416                                                                         std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
417                                                                         parserData.push_back(nuget + ":" + assemblyName);
418                                                                         _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
419                                                                 }
420                                                         }
421                                                 }
422                                         }
423                                 }
424                                 appDependencies.clear();
425                                 ifs.close();
426                         }
427                 }
428         } catch (const Json::Exception& error) {
429                 _ERR("Failed to parse Json: %s", error.what());
430         }
431         return parserData;
432 }
433
434 std::vector<std::string> getLibrariesInfo(const std::string& rootPath)
435 {
436         std::vector<std::string> LibrariesInfo;
437         std::string binDir = concatPath(rootPath, "bin");
438         if (!exist(binDir))
439                 return LibrariesInfo;
440
441         auto convert = [&LibrariesInfo](const std::string& filepath, const std::string& filename) {
442                 if (filename.find(".so", filename.size() - 3) != std::string::npos) {
443                         std::string buffer = SHA256(filepath);
444                         LibrariesInfo.push_back(filepath + ":" + buffer);
445                         _INFO("Library : [%s] / SHA256 : [%s]", filename.c_str(), buffer.c_str());
446                 }
447         };
448         scanFilesInDirectory(binDir, convert, -1);
449
450         return LibrariesInfo;
451 }
452
453 // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
454 static int tlc_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
455 {
456         char *pkgId = NULL;
457         char *root = NULL;
458         std::string rootPath;
459
460         int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
461         if (ret != PMINFO_R_OK) {
462                 _SERR("Failed to get pkgid");
463                 return -1;
464         }
465
466         ret = pkgmgrinfo_appinfo_get_root_path(handle, &root);
467         if (ret != PMINFO_R_OK) {
468                 _SERR("Failed to get root path");
469                 return -1;
470         }
471         rootPath = std::string(root);
472
473         for (auto& librarySha : getLibrariesInfo(rootPath)) {
474                 std::string library = librarySha.substr(0, librarySha.find(':'));
475                 if (exist(library)) {
476                         std::string fileSha = library.substr(library.rfind('/') + 1) + ".." + librarySha.substr(librarySha.find(':') + 1);
477                         char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
478                         insertDB(tlc_db, sql);
479                         restore_library.push_back(fileSha);
480                         sqlite3_free(sql);
481                 }
482         }
483         return 0;
484 }
485
486 tac_error_e tlc_restoreDB()
487 {
488         if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
489                 _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB);
490                 return TAC_ERROR_UNKNOWN;
491         }
492
493         std::string dbRestoreJournal = TLC_APP_LIST_RESTORE_DB + std::string("-journal");
494         if (!removeFile(dbRestoreJournal)) {
495                 _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
496                 return TAC_ERROR_UNKNOWN;
497         }
498
499         tlc_db = createDB(TLC_APP_LIST_RESTORE_DB, CREATE_TLC_DB_TABLE);
500         if (!tlc_db) {
501                 _SERR("Sqlite create error");
502                 return TAC_ERROR_UNKNOWN;
503         }
504         sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
505
506         pkgmgrinfo_appinfo_metadata_filter_h handle;
507         int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
508         if (ret != PMINFO_R_OK) {
509                 return TAC_ERROR_UNKNOWN;
510         }
511
512         ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
513         if (ret != PMINFO_R_OK) {
514                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
515                 return TAC_ERROR_UNKNOWN;
516         }
517
518         ret = pkgmgrMDFilterForeach(handle, tlc_restoreDBCb, NULL);
519         if (ret != 0) {
520                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
521                 return TAC_ERROR_UNKNOWN;
522         }
523
524         pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
525
526         if (tlc_db) {
527                 closeDB(tlc_db);
528                 tlc_db = NULL;
529         }
530
531         if (!copyFile(TLC_APP_LIST_RESTORE_DB, TLC_APP_LIST_DB)) {
532                 _SERR("Failed to copy of %s", TLC_APP_LIST_DB);
533                 return TAC_ERROR_UNKNOWN;
534         }
535         if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
536                 _SERR("Failed to remove of %s", TLC_APP_LIST_RESTORE_DB);
537                 return TAC_ERROR_UNKNOWN;
538         }
539
540         std::string dbJournal = TLC_APP_LIST_DB + std::string("-journal");
541         if (!copyFile(dbRestoreJournal, dbJournal)) {
542                 _SERR("Failed to copy of %s", dbJournal.c_str());
543                 return TAC_ERROR_UNKNOWN;
544         }
545         if (!removeFile(dbRestoreJournal)) {
546                 _SERR("Failed to remove of %s", dbRestoreJournal.c_str());
547                 return TAC_ERROR_UNKNOWN;
548         }
549
550         auto convert = [](const std::string& path, const std::string& filename) {
551                 bool isExist = false;
552                 for (auto& library : restore_library) {
553                         if (!strcmp(filename.c_str(), library.c_str())) {
554                                 isExist = true;
555                                 break;
556                         }
557                 }
558                 if (!isExist) {
559                         if (!removeFile(path)) {
560                                 _ERR("Failed to remove of %s", path.c_str());
561                         }
562                 }
563         };
564
565         scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
566
567         return TAC_ERROR_NONE;
568 }