sptr<SPackage::Data> SPackage::Pool::DataFor(const SString& pkgName)
{
	SLocker::Autolock lock(m_lock);

	sptr<SPackage::Data> data = m_packages.ValueFor(pkgName).promote();

	if (data == NULL)
	{
		SString catPath(key_packages_packages);
		catPath.PathAppend(pkgName);

		SValue value = SContext::UserContext().Lookup(catPath);
		
		SString path = value[key_path].AsString();

		struct stat sb;
		int err = stat(path.String(), &sb);

		if (err != 0)
		{
			berr << "*** Error construting package '"<< pkgName << "' err = " << strerror(errno) << endl;
		}
		else
		{
			data = new SPackage::Data(pkgName, path);
			m_packages.AddItem(pkgName, data);
		}
	}
	
	return data;
}
Ejemplo n.º 2
0
void Platform::MakeFullPathName(const string& inPath, string& outPath, const string* cwd)
{
    char bspath[1024];
    strncpy(bspath, inPath.c_str(), sizeof(bspath));
    bspath[sizeof(bspath)-1] = 0;
   
    for(U32 i = 0;i < strlen(bspath);++i)
    {
        if(bspath[i] == '\\')
            bspath[i] = '/';
    }

    if(Platform::IsFullPath(bspath))
    {
        // Already a full path
        outPath = bspath;
        #if defined(WIN32)
            _resolveLeadingSlash(outPath);
        #endif
        
        return;
    }

    string currentDir;
    if(cwd == NULL)
        Platform::getCurrentDirectory(currentDir);
    else
        currentDir = *cwd;

    const U32 size = 1024;
    char buffer[size];
    strncpy(buffer, currentDir.c_str(), size);
    buffer[size-1] = 0;

    char *ptr = bspath;
    char *slash = NULL;
    char *endptr = buffer + strlen(buffer) - 1;

    do
    {
        slash = strchr(ptr, '/');
        if(slash)
        {
            *slash = 0;

            // Directory

            if(strcmp(ptr, "..") == 0)
            {
                // Parent
                endptr = strrchr(buffer, '/');
                *endptr = 0;
                endptr--;
            }
            else if(strcmp(ptr, ".") == 0)
            {
                // Current dir
            }
            else if(endptr)
            {
                catPath(endptr, ptr, size - (endptr - buffer));
                endptr += strlen(endptr) - 1;
            }
         
            ptr = slash + 1;
        }
        else if(endptr)
        {
            // File

            catPath(endptr, ptr, size - (endptr - buffer));
            endptr += strlen(endptr) - 1;
        }

    } while(slash);

    outPath = buffer;
}