Esempio n. 1
0
void RemoteProtocol::stat(const KUrl &url)
{
	kDebug(1220) << "RemoteProtocol::stat: " << url;

	QString path = url.path();
	if ( path.isEmpty() || path == "/" )
	{
		// The root is "virtual" - it's not a single physical directory
		KIO::UDSEntry entry;
		m_impl.createTopLevelEntry( entry );
		statEntry( entry );
		finished();
		return;
	}

	if (m_impl.isWizardURL(url))
	{
		KIO::UDSEntry entry;
		if (m_impl.createWizardEntry(entry))
		{
			statEntry(entry);
			finished();
		}
		else
		{
			error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl());
		}
		return;
	}

	int second_slash_idx = url.path().indexOf( '/', 1 );
	const QString root_dirname = url.path().mid( 1, second_slash_idx-1 );

	if ( second_slash_idx==-1 || ( (int)url.path().length() )==second_slash_idx+1 )
	{
		KIO::UDSEntry entry;
		if (m_impl.statNetworkFolder(entry, root_dirname))
		{
			statEntry(entry);
			finished();
			return;
		}
	}
	else
	{
		KUrl target = m_impl.findBaseURL(  root_dirname );
		kDebug( 1220 ) << "possible redirection target : " << target;
		if (  target.isValid() )
		{
			if ( second_slash_idx < 0 ) {
				second_slash_idx = url.path().size();
			}
			kDebug(1220) << "complete redirection target : " << target;
			target.addPath( url.path().remove( 0, second_slash_idx ) );
			redirection( target );
			finished();
			return;
		}
	}

	error(KIO::ERR_MALFORMED_URL, url.prettyUrl());
}
Esempio n. 2
0
void PakProtocol::stat(const KURL &url) {
	kdDebug(PAK_DEBUG_ID) << "Entering stat()" << endl;
	QString path;
	KIO::UDSEntry entry;
	KIO::Error errorNum;
	if ( !checkNewFile( url, path, errorNum ) )
	{
		// We may be looking at a real directory - this happens
		// when pressing up after being in the root of an archive
		if ( errorNum == KIO::ERR_CANNOT_OPEN_FOR_READING )
		{
			// If we cannot open, it might be a problem with the archive header (e.g. unsupported format)
			// Therefore give a more specific error message
			error( KIO::ERR_SLAVE_DEFINED,
					i18n( "Could not open the file, probably due to an unsupported file format.\n%1")
					.arg( url.prettyURL() ) );
			return;
		}
		else if ( errorNum != KIO::ERR_IS_DIRECTORY )
		{
			// We have any other error
			error( errorNum, url.prettyURL() );
			return;
		}
		// Real directory. Return just enough information for KRun to work
		KIO::UDSAtom atom;
		atom.m_uds = KIO::UDS_NAME;
		atom.m_str = url.fileName();
		entry.append( atom );
		kdDebug( PAK_DEBUG_ID ) << "ArchiveProtocol::stat returning name=" << url.fileName() << endl;

		KDE_struct_stat buff;
		if ( KDE_stat( QFile::encodeName( url.path() ), &buff ) == -1 )
		{
			// Should not happen, as the file was already stated by checkNewFile
			error( KIO::ERR_COULD_NOT_STAT, url.prettyURL() );
			return;
		}

		atom.m_uds = KIO::UDS_FILE_TYPE;
		atom.m_long = buff.st_mode & S_IFMT;
		entry.append( atom );

		statEntry( entry );

		finished();

		// And let go of the tar file - for people who want to unmount a cdrom after that
		delete _pakFile;
		_pakFile = 0L;
		return;
	}

	const KArchiveDirectory* root = _pakFile->directory();
	const KArchiveEntry* archiveEntry;
	if ( path.isEmpty() )
	{
		path = QString::fromLatin1( "/" );
		archiveEntry = root;
	} else {
		path = QString::fromLocal8Bit(remoteEncoding()->encode(path));
		archiveEntry = root->entry( path );
	}
	if ( !archiveEntry )
	{
		error( KIO::ERR_DOES_NOT_EXIST, url.prettyURL() );
		return;
	}

	createUDSEntry( archiveEntry, entry );
	statEntry( entry );

	finished();

	/*kdDebug(PAK_DEBUG_ID) << "Entering stat()" << endl;
	KIO::UDSEntry entry;
	createUDSEntry(NULL, entry);
	kdDebug(PAK_DEBUG_ID) << "Giving file away" << endl;
	statEntry(entry);
	finished();
	kdDebug(PAK_DEBUG_ID) << "-<> Exiting stat()" << endl;*/
}