Пример #1
0
const bool OTPaths::PathExists(const OTString & strPath)
{
	if (!strPath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strPath" ); OT_ASSERT(false); }


	// remove trailing backslash for stat
	std::string l_strPath(strPath.Get());
	l_strPath = (OTString::replace_chars(l_strPath,"\\",'/'));  // all \ to /

	//std::string l_strPath_stat = l_strPath;
	std::string l_strPath_stat("");
	
	// remove last / if it exists (for l_strPath_stat)
	if ('/' == *l_strPath.rbegin())
		l_strPath_stat = l_strPath.substr(0, l_strPath.size()-1);
	else l_strPath_stat = l_strPath;

	struct stat st; 
    memset(&st, 0, sizeof(st));
    
	if (0 == stat(l_strPath_stat.c_str(), &st)) // good we have at-least on a node
	{
		if ('/' != *l_strPath.rbegin())
		{
			long temp_l=0;
			return FileExists(strPath,temp_l);
		}
		else
		{
			return FolderExists(strPath);
		}
	}
	return false;
}
Пример #2
0
const bool OTPaths::FileExists(const OTString & strFilePath, long & nFileLength)
{
	if (!strFilePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strFilePath" ); OT_ASSERT(false); }


	// remove trailing backslash for stat
	std::string l_strPath(strFilePath.Get());
	l_strPath = (OTString::replace_chars(l_strPath,"\\",'/'));  // all \ to /

	//std::string l_strPath_stat = l_strPath;
	std::string l_strPath_stat("");
	
	// remove last / if it exists (for l_strPath_stat)
	if ('/' == *l_strPath.rbegin())
		l_strPath_stat = l_strPath.substr(0, l_strPath.size()-1);
	else l_strPath_stat = l_strPath;


	if ('/' != *l_strPath.rbegin())
	{


		int status=0;
#ifdef _WIN32
		struct _stat st_buf;
        memset(&st_buf, 0, sizeof(st_buf));
		char filename[4086];	// not sure about this buffer,
		// on windows paths cannot be longer than 4086,
		// so it should be fine... needs more research.
		strcpy_s(filename,l_strPath_stat.c_str());
		status = _stat(filename, &st_buf );
#else
		struct stat st_buf;
        memset(&st_buf, 0, sizeof(st_buf));
		status = stat (l_strPath.c_str(), &st_buf);
#endif

		// check for file
		if (S_ISREG(st_buf.st_mode))
		{
			// good we have a file.
			size_t lFileLength = st_buf.st_size;
			nFileLength = static_cast<long>(lFileLength);
			return true;
		}
	}
	return false;
}
Пример #3
0
// static
bool OTPaths::PathExists(const String& strPath)
{
    if (!strPath.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strPath"
              << " passed in!\n";
        OT_FAIL;
    }

    // remove trailing backslash for stat
    std::string l_strPath(strPath.Get());
    l_strPath = (String::replace_chars(l_strPath, "\\", '/')); // all \ to /

    // std::string l_strPath_stat = l_strPath;
    std::string l_strPath_stat("");

    // remove last / if it exists (for l_strPath_stat)
    if ('/' == *l_strPath.rbegin())
        l_strPath_stat = l_strPath.substr(0, l_strPath.size() - 1);
    else
        l_strPath_stat = l_strPath;

    struct stat st;
    memset(&st, 0, sizeof(st));

    if (0 ==
        stat(l_strPath_stat.c_str(), &st)) // good we have at-least on a node
    {
        if ('/' != *l_strPath.rbegin()) {
            int64_t temp_l = 0;
            return FileExists(strPath, temp_l);
        }
        else {
            return FolderExists(strPath);
        }
    }
    return false;
}