#include <unistd.h>
#include <string.h>
+#include <fstream>
+
#include "common.h"
#ifdef LOG_TAG
#undef __STR
#undef __XSTR
-
+#if 0
static std::string replace(std::string &str, const std::string& from, const std::string& to)
{
size_t startPos = 0;
}
return str;
}
+#endif
static void smack_(const char* dllPath, const char* label)
{
// get reference API directory ([DEVICE_API_DIR]/ref)
int len = strlen(__DEVICE_API_DIR);
- char* refAPIDir = (char*)calloc(len + 4, 1);
- snprintf(refAPIDir, len + 4, "%s%s", __DEVICE_API_DIR, "/ref");
+ char* refAPIDir = (char*)calloc(len + 5, 1);
+ if (!refAPIDir) {
+ printf("fail to allocate memory for reference API directory\n");
+ return;
+ }
+ snprintf(refAPIDir, len + 5, "%s%s", __DEVICE_API_DIR, "/ref");
tpaDir.push_back(refAPIDir);
std::string tpa;
}
}
+void removeNiUnderDirs(const char* rootPaths[], int count)
+{
+ auto convert = [](const char* path, const char* name) {
+ std::string ni;
+ if (isNativeImage(path)) {
+ remove(path);
+ }
+ };
+
+ for (int i = 0; i < count; i++)
+ scanFilesInDir(rootPaths[i], convert, -1);
+}
+
+void removeNiPlatform()
+{
+ std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll");
+ std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll");
+ std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup");
+
+ if (fileNotExist(coreLibBackup)) {
+ return;
+ }
+
+ if (remove(coreLib.c_str())) {
+ _ERR("Failed to remove System.Private.CoreLib native image file");
+ }
+
+ rename(coreLibBackup.c_str(), coreLib.c_str());
+
+ const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"};
+
+ removeNiUnderDirs(platformDirs, 3);
+}
+
void createNiPlatform()
{
createCoreLibNI();
createNiUnderDirs(rootPaths, count, nullptr);
}
+int removeNiUnderPkgRoot(const char* pkgName)
+{
+ std::string pkgRoot;
+ if (getRootPath(pkgName, pkgRoot) < 0)
+ return 1;
+
+ std::string binDir = concatPath(pkgRoot, "bin");
+ std::string libDir = concatPath(pkgRoot, "lib");
+ _INFO("bindir : %s", binDir.c_str());
+ _INFO("libdir : %s", libDir.c_str());
+
+ const char* paths[] = {
+ binDir.c_str(),
+ libDir.c_str()
+ };
+
+ removeNiUnderDirs(paths, 2);
+
+ return 0;
+}
+
+
int createNiUnderPkgRoot(const char* pkgName)
{
std::string pkgRoot;
if (getRootPath(pkgName, pkgRoot) < 0)
return 1;
+ // get interval value
+ const char* intervalFile = "/usr/share/dotnet.tizen/lib/crossgen_interval.txt";
+ int interval = 0;
+ std::ifstream inFile(intervalFile);
+ if (inFile) {
+ _INFO("crossgen_interval.txt is found");
+ inFile >> interval;
+ } else {
+ _INFO("fail to read crossgen_interval.txt file");
+ }
+
std::string binDir = concatPath(pkgRoot, "bin");
std::string libDir = concatPath(pkgRoot, "lib");
_INFO("bindir : %s", binDir.c_str());
// change smack label for generated ni file.
std::string label = "User::Pkg::" + std::string(pkgName) + "::RO";
- createNiUnderDirs(paths, 2, [label](const char* ni) {
+ createNiUnderDirs(paths, 2, [label, interval](const char* ni) {
smack_(ni, label.c_str());
+ if (interval != 0) {
+ _INFO("sleep %d usec", interval);
+ usleep(interval);
+ }
});
return 0;