}
}
+static void swapExtensionRpkFiles(std::vector<std::string>& paths, NIOption* opt)
+{
+ std::vector<std::string> dllList;
+ std::vector<std::string> niList;
+ std::string path = paths.back();
+ try {
+ for (auto& file : bf::recursive_directory_iterator(path)) {
+ std::string filePath = file.path().string();
+ if (isNativeImage(filePath)) {
+ niList.push_back(filePath);
+ }
+ else if (isManagedAssembly(filePath)) {
+ dllList.push_back(filePath);
+ }
+ }
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return;
+ }
+
+ for (auto& dll : dllList) {
+ rename(dll.c_str(), changeExtension(dll, ".dll", ".dll.backup").c_str());
+ }
+ for (auto& ni : niList) {
+ std::string dll = changeExtension(ni, ".ni.dll", ".dll");
+ bf::create_symlink(getFileName(ni), dll);
+ copySmackAndOwnership(ni, dll, true);
+ }
+}
+
static ni_error_e doAOTList(std::vector<std::string>& dllList, const std::string& refPaths, NIOption* opt)
{
ni_error_e ret = NI_ERROR_NONE;
renameAppNITmpPath(opt);
}
+ if (opt->isRPK) {
+ swapExtensionRpkFiles(paths, opt);
+ }
+
return ret;
}
_SERR("Failed to get root path from [%s]", pkgId.c_str());
return NI_ERROR_INVALID_PACKAGE;
}
+ opt->isRPK = isRPK(pkgId);
- return createNIUnderPkgRootWithPath(rootPath, opt, isRPK(pkgId));
+ return createNIUnderPkgRootWithPath(rootPath, opt);
}
-ni_error_e createNIUnderPkgRootWithPath(const std::string& rootPath, NIOption* opt, bool rpk)
+ni_error_e createNIUnderPkgRootWithPath(const std::string& rootPath, NIOption* opt)
{
if (!isR2RImage(concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll"))) {
_SERR("The native image of System.Private.CoreLib does not exist.\n"
}
std::string targetDirs;
- if (rpk) {
+ if (opt->isRPK) {
opt->flags &= ~NI_FLAGS_APPNI; // added to exclude logic of APP_NI
opt->flags |= NI_FLAGS_NO_PIPELINE; // added the flag to set the output path
void removeNIUnderDirs(const std::string& rootPaths)
{
auto convert = [](const std::string& path, const std::string& filename) {
- //The .ni.dll file can be renamed .dll.
- if (isR2RImage(path) && isNativeImage(path)) {
- std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll");
- if (exist(assemblyPath)) {
- if (remove(path.c_str())) {
- _SERR("Failed to remove %s", path.c_str());
+ std::string assemblyBackupPath = changeExtension(path, ".ni.dll", ".dll.backup");
+ if (exist(assemblyBackupPath)) {
+ // The RPK type is that .dll is a .ni.dll file and .dll.backup is a .dll file.
+ // So, change the name of the .dll.backup file to the .dll file.
+ if (strstr(filename.c_str(), ".dll.backup") != NULL) {
+ std::string originPath = changeExtension(path, ".dll.backup", ".dll");
+ std::string niFile = changeExtension(path, ".dll.backup", ".ni.dll");
+ if (rename(path.c_str(), originPath.c_str())) {
+ _SERR("Failed to rename %s", path.c_str());
+ }
+ if (remove(niFile.c_str())) {
+ _SERR("Failed to remove %s", niFile.c_str());
+ }
+ }
+ } else {
+ //The .ni.dll file can be renamed .dll.
+ if (isR2RImage(path) && isNativeImage(path)) {
+ std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll");
+ if (exist(assemblyPath)) {
+ if (remove(path.c_str())) {
+ _SERR("Failed to remove %s", path.c_str());
+ }
+ } else {
+ _SOUT("%s cannot be removed because there is no %s", path.c_str(), assemblyPath.c_str());
}
- } else {
- _SOUT("%s cannot be removed because there is no %s", path.c_str(), assemblyPath.c_str());
}
}
};