bf::exists() can throw exception. To avoid crash by exception, exist() which wrap bf::exists() is added.
*/
void copySmackAndOwnership(const std::string& fromPath, const std::string& toPath, bool isSymlink = false);
+/**
+ * @brief check whether the path exists or not.
+ * @param[in] source path
+ * @return return true when the path exist.
+ */
+bool exist(const bf::path& path);
+
/**
* @brief create the new directory.
* @param[in] source path
std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
- if (bf::exists(concatPath(binPath, assembly))) {
+ if (exist(concatPath(binPath, assembly))) {
if (isCreateTacDir) {
if (!copyFile(concatPath(binPath, assembly), concatPath(tac_version_dir, assembly))) {
_ERR("Failed to copy of %s", assembly.c_str());
std::string filename = library.substr(library.rfind('/') + 1);
std::string fileSha = filename + ".." + librarySha.substr(librarySha.find(':') + 1);
bool fileCopied = false;
- if (!bf::exists(concatPath(tlcDir, fileSha))) {
+ if (!exist(concatPath(tlcDir, fileSha))) {
if (!copyFile(library, concatPath(tlcDir, fileSha))) {
_ERR("Failed to copy of %s", filename.c_str());
continue;
std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
- if (!bf::exists(tac_version_dir)) {
+ if (!exist(tac_version_dir)) {
_INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
if (!createDir(tac_version_dir)) {
_ERR("Cannot create directory: %s", tac_version_dir.c_str());
std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
- if (!bf::exists(tac_version_dir)) {
+ if (!exist(tac_version_dir)) {
_INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
if (!createDir(tac_version_dir)) {
_ERR("Cannot create directory: %s", tac_version_dir.c_str());
for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
- if (bf::exists(tacDir) && bf::exists(concatPath(tacDir, assemblyName))) {
+ if (exist(tacDir) && exist(concatPath(tacDir, assemblyName))) {
parserData.push_back(nugetPackage);
}
}
std::string binDir = concatPath(rootPath, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
- if (bf::exists(tacDir)) {
+ if (exist(tacDir)) {
try {
for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
std::string symPath = symlinkAssembly.path().string();
std::string binDir = concatPath(rootPath, "bin");
std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
- if (!bf::exists(tacDir)) {
+ if (!exist(tacDir)) {
if (!createDir(tacDir)) {
fprintf(stderr, "Cannot create directory: %s\n", tacDir.c_str());
return TAC_ERROR_UNKNOWN;
std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
std::string nugetPath = concatPath(__DOTNET_DIR, nugetPackage);
- if (bf::exists(nugetPath)) {
+ if (exist(nugetPath)) {
std::string originPath = concatPath(nugetPath, assemblyName);
- if (bf::exists(originPath)) {
+ if (exist(originPath)) {
enableNuget.push_back(originPath);
}
}
}
for (auto& originPath : enableNuget) {
- if (bf::exists(originPath)) {
+ if (exist(originPath)) {
std::string fileName = originPath.substr(originPath.rfind('/') + 1);
std::string NIFileName = fileName.substr(0, fileName.rfind(".dll")) + ".ni.dll";
- if (bf::exists(binNIDir)) {
+ if (exist(binNIDir)) {
std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
- if (bf::exists(originNIPath)) {
+ if (exist(originNIPath)) {
bf::create_symlink(originNIPath, concatPath(tacDir, NIFileName));
fprintf(stdout, "%s symbolic link file generated successfully.\n", concatPath(tacDir, NIFileName).c_str());
copySmackAndOwnership(tacDir.c_str(), concatPath(tacDir, NIFileName).c_str(), true);
std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json";
std::string depsJsonPath = concatPath(rootPath, depsJsonName);
try {
- if (bf::exists(depsJsonPath)) {
+ if (exist(depsJsonPath)) {
std::ifstream ifs(depsJsonPath);
Json::CharReaderBuilder reader;
Json::Value root;
{
std::vector<std::string> LibrariesInfo;
std::string runtimesDir = concatPath(rootPath, "bin/runtimes");
- if (!bf::exists(runtimesDir))
+ if (!exist(runtimesDir))
return LibrariesInfo;
auto convert = [&LibrariesInfo](const std::string& filepath, const std::string& filename) {
for (auto& librarySha : getLibrariesInfo(rootPath)) {
std::string library = librarySha.substr(0, librarySha.find(':'));
- if (bf::exists(library)) {
+ if (exist(library)) {
std::string fileSha = library.substr(library.rfind('/') + 1) + ".." + librarySha.substr(librarySha.find(':') + 1);
char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
insertDB(tlc_db, sql);
static bool copyOwnershipAndPermissions(const bf::path& path, const bf::path& path2)
{
- if (!bf::exists(path)) {
+ if (!exist(path)) {
_ERR("Failed to copy ownership and permissions from %s to %s", path.c_str(), path2.c_str());
return false;
}
return true;
}
+bool exist(const bf::path& path)
+{
+ bs::error_code error;
+ bf::exists(path, error);
+ if (error) {
+ _ERR("Failed to check %s exists : %s", path.c_str(), error.message().c_str());
+ return false;
+ }
+ return true;
+}
+
bool createDir(const bf::path& path)
{
- if (bf::exists(path)) {
+ if (exist(path)) {
return true;
}
bs::error_code error;
{
try {
// Check whether the function call is valid
- if (!bf::exists(path1) || !bf::is_directory(path1)) {
+ if (!exist(path1) || !bf::is_directory(path1)) {
_ERR("Source directory %s does not exist or is not a directory", path1.c_str());
return false;
}
- if (!bf::exists(path2)) {
+ if (!exist(path2)) {
// Create the destination directory
if (!createDir(path2)) {
_ERR("Unable to create destination directory %s", path2.c_str());
bf::path current(file->path());
bf::path target = path2 / current.filename();
if (bf::is_symlink(symlink_status(current))) {
- if ((flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE)) && bf::exists(target)) {
+ if ((flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE)) && exist(target)) {
continue;
}
bs::error_code error;
return false;
}
} else {
- if ((flags & FS_MERGE_SKIP) && bf::exists(target)) {
+ if ((flags & FS_MERGE_SKIP) && exist(target)) {
continue;
}
bf::path destination = target;
bool copyFile(const bf::path& path1, const bf::path& path2)
{
bs::error_code error;
- if (!bf::exists(path1)) {
+ if (!exist(path1)) {
return false;
}
bf::copy_file(path1, path2, bf::copy_option::overwrite_if_exists, error);
bool moveFile(const bf::path& path1, const bf::path& path2)
{
- if (!bf::exists(path1) || bf::exists(path2)) {
+ if (!exist(path1) || exist(path2)) {
return false;
}
bs::error_code error;
bool removeFile(const bf::path& path)
{
- if (!bf::exists(path)) {
+ if (!exist(path)) {
return true;
}
bs::error_code error;
bool removeAll(const bf::path& path)
{
- if (!exists(path)) {
+ if (!exist(path)) {
return true;
}
bs::error_code error;