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