You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
306 lines
6.7 KiB
306 lines
6.7 KiB
15 years ago
|
/***************************************************************************
|
||
4 years ago
|
virt.cpp
|
||
15 years ago
|
-------------------
|
||
|
begin : Fri Dec 5 2003
|
||
|
copyright : (C) 2003 by Shie Erlich & Rafi Yanai
|
||
|
email :
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
14 years ago
|
#include <tqfile.h>
|
||
15 years ago
|
#include <kurl.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
13 years ago
|
#include <tdeversion.h>
|
||
15 years ago
|
#include <kinstance.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
#include "virt.h"
|
||
|
|
||
12 years ago
|
using namespace TDEIO;
|
||
15 years ago
|
|
||
|
#define VIRT_VFS_DB "virt_vfs.db"
|
||
|
#define VIRT_PROTOCOL "virt"
|
||
|
|
||
|
#if KDE_IS_VERSION(3,4,0)
|
||
|
extern "C" { int KDE_EXPORT kdemain( int argc, char **argv ); }
|
||
|
#else
|
||
|
extern "C" { int kdemain( int argc, char **argv ); }
|
||
|
#endif
|
||
|
|
||
|
#define KrDEBUG(X...){\
|
||
12 years ago
|
FILE* f = fopen("/tmp/tdeio_virt.log","a+");\
|
||
15 years ago
|
fprintf(f,X);\
|
||
|
fclose(f);\
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDict<KURL::List> VirtProtocol::kioVirtDict;
|
||
12 years ago
|
TDEConfig* VirtProtocol::tdeio_virt_db;
|
||
15 years ago
|
|
||
|
int kdemain( int argc, char **argv ) {
|
||
12 years ago
|
TDEInstance instance( "tdeio_virt" );
|
||
15 years ago
|
|
||
|
if ( argc != 4 ) {
|
||
12 years ago
|
fprintf( stderr, "Usage: tdeio_virt protocol domain-socket1 domain-socket2\n" );
|
||
15 years ago
|
exit( -1 );
|
||
|
}
|
||
|
|
||
|
VirtProtocol slave( argv[ 2 ], argv[ 3 ] );
|
||
|
slave.dispatchLoop();
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
VirtProtocol::VirtProtocol( const TQCString &pool, const TQCString &app ) : SlaveBase( "virt", pool, app ) {
|
||
12 years ago
|
tdeio_virt_db = new TDEConfig(VIRT_VFS_DB,false,"data");
|
||
15 years ago
|
}
|
||
|
|
||
|
VirtProtocol::~VirtProtocol() {
|
||
12 years ago
|
delete tdeio_virt_db;
|
||
15 years ago
|
}
|
||
|
|
||
|
void VirtProtocol::del(KURL const & /*url */, bool /* isFile */ ){
|
||
|
// KRDEBUG(url.path());
|
||
|
|
||
12 years ago
|
messageBox(TDEIO::SlaveBase::QuestionYesNo,
|
||
6 years ago
|
"",
|
||
15 years ago
|
i18n("Virtulal delete"),
|
||
|
i18n("remove from virtual space"),
|
||
|
i18n("really delete")
|
||
|
);
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::copy( const KURL &src, const KURL &dest, int /* permissions */, bool /* overwrite */ ){
|
||
14 years ago
|
TQString path = dest.path( -1 ).mid( 1 );
|
||
13 years ago
|
path = path.left(path.findRev("/"));
|
||
15 years ago
|
if ( path.isEmpty() ) path = "/";
|
||
|
|
||
|
if( addDir(path) ){
|
||
|
kioVirtDict[ path ]->append(src);
|
||
|
save();
|
||
|
}
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
14 years ago
|
bool VirtProtocol::addDir(TQString& path){
|
||
15 years ago
|
|
||
|
if( kioVirtDict[ path ] ) return true;
|
||
|
|
||
14 years ago
|
TQString updir;
|
||
13 years ago
|
if( !path.contains("/") ) updir = "/";
|
||
|
else updir = path.left(path.findRev("/"));
|
||
|
TQString name = path.mid(path.findRev("/")+1);
|
||
15 years ago
|
|
||
|
if( addDir(updir) ){
|
||
|
KURL url;
|
||
14 years ago
|
if( updir == "/" ) url = TQString("virt:/")+name;
|
||
|
else url = TQString("virt:/")+updir+"/"+name;
|
||
15 years ago
|
kioVirtDict[ updir ]->append( url );
|
||
|
|
||
|
KURL::List* temp = new KURL::List();
|
||
13 years ago
|
kioVirtDict.replace( path, temp );
|
||
15 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::mkdir(const KURL& url,int){
|
||
|
if( url.protocol() != VIRT_PROTOCOL ){
|
||
|
redirection(url);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString path = url.path( -1 ).mid( 1 );
|
||
15 years ago
|
if ( path.isEmpty() ) path = "/";
|
||
|
|
||
|
if( kioVirtDict[ path ] ){
|
||
12 years ago
|
error( TDEIO::ERR_DIR_ALREADY_EXIST, url.path() );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
addDir(path);
|
||
|
|
||
|
save();
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::listDir( const KURL & url ) {
|
||
|
if( url.protocol() != VIRT_PROTOCOL ){
|
||
|
redirection(url);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
load();
|
||
|
|
||
14 years ago
|
TQString path = url.path( -1 ).mid( 1 );
|
||
15 years ago
|
if ( path.isEmpty() ) path = "/";
|
||
|
|
||
|
KURL::List* urlList = kioVirtDict[ path ];
|
||
|
if ( !urlList ) {
|
||
|
error(ERR_CANNOT_ENTER_DIRECTORY,url.path());
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
UDSEntryList dirList;
|
||
|
KURL::List::iterator it;
|
||
|
for ( it = urlList->begin() ; it != urlList->end() ; ++it ) {
|
||
|
KURL entry_url = *it;
|
||
|
// translate url->UDS_ENTRY
|
||
|
UDSEntry entry;
|
||
|
if( entry_url.protocol() == VIRT_PROTOCOL ){
|
||
|
local_entry(entry_url,entry);
|
||
|
} else {
|
||
|
UDSAtom atom;
|
||
|
|
||
|
atom.m_uds = UDS_NAME;
|
||
|
atom.m_str = url.isLocalFile() ? url.path() : entry_url.prettyURL();
|
||
|
entry.append(atom);
|
||
|
|
||
|
atom.m_uds = UDS_URL;
|
||
|
atom.m_str = entry_url.url();
|
||
|
entry.append(atom);
|
||
|
}
|
||
|
|
||
|
dirList.append(entry);
|
||
|
}
|
||
|
|
||
|
totalSize(dirList.size());
|
||
|
listEntries(dirList);
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::stat( const KURL & url ) {
|
||
|
if( url.protocol() != VIRT_PROTOCOL ){
|
||
|
redirection(url);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
UDSEntry entry;
|
||
|
local_entry(url,entry);
|
||
|
|
||
|
statEntry(entry);
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::get( const KURL & url ) {
|
||
|
if( url.protocol() != VIRT_PROTOCOL ){
|
||
|
redirection(url);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
bool VirtProtocol::rewriteURL(const KURL& /* src */, KURL&){
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool VirtProtocol::save(){
|
||
|
lock();
|
||
|
|
||
12 years ago
|
TDEConfig* db = new TDEConfig(VIRT_VFS_DB,false,"data");;
|
||
15 years ago
|
|
||
|
db->setGroup("virt_db");
|
||
14 years ago
|
TQDictIterator<KURL::List> it( kioVirtDict ); // See TQDictIterator
|
||
15 years ago
|
for( ; it.current(); ++it ){
|
||
|
KURL::List::iterator url;
|
||
14 years ago
|
TQStringList entry;
|
||
15 years ago
|
for ( url = it.current()->begin() ; url != it.current()->end() ; ++url ) {
|
||
|
entry.append( (*url).url() );
|
||
|
}
|
||
|
db->writeEntry(it.currentKey(),entry);
|
||
|
}
|
||
|
|
||
|
db->sync();
|
||
|
delete(db);
|
||
|
|
||
|
unlock();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool VirtProtocol::load(){
|
||
|
lock();
|
||
|
|
||
12 years ago
|
TDEConfig* db = new TDEConfig(VIRT_VFS_DB,false,"data");
|
||
15 years ago
|
db->setGroup("virt_db");
|
||
|
|
||
14 years ago
|
TQMap<TQString, TQString> map = db->entryMap("virt_db");
|
||
|
TQMap<TQString, TQString>::Iterator it;
|
||
15 years ago
|
KURL::List* urlList;
|
||
|
for ( it = map.begin(); it != map.end(); ++it ) {
|
||
|
urlList = new KURL::List( db->readListEntry(it.key()) );
|
||
13 years ago
|
kioVirtDict.replace( it.key(),urlList );
|
||
15 years ago
|
}
|
||
|
|
||
|
if( !kioVirtDict["/" ]){
|
||
|
urlList = new KURL::List();
|
||
13 years ago
|
kioVirtDict.replace( "/", urlList );
|
||
15 years ago
|
}
|
||
|
|
||
|
unlock();
|
||
|
|
||
|
delete(db);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void VirtProtocol::local_entry(const KURL& url,UDSEntry& entry){
|
||
14 years ago
|
TQString path = url.path( -1 ).mid( 1 );
|
||
15 years ago
|
if ( path.isEmpty() ) path = "/";
|
||
|
|
||
|
UDSAtom atom;
|
||
|
|
||
|
atom.m_uds = UDS_NAME;
|
||
|
atom.m_str = url.fileName();
|
||
|
entry.append(atom);
|
||
|
|
||
|
atom.m_uds = UDS_URL;
|
||
|
atom.m_str = url.url();
|
||
|
entry.append(atom);
|
||
|
|
||
|
atom.m_uds = UDS_FILE_TYPE;
|
||
|
atom.m_long = S_IFDIR;
|
||
|
entry.append(atom);
|
||
|
|
||
|
atom.m_uds = UDS_ACCESS;
|
||
|
atom.m_long = 0700;
|
||
|
entry.append(atom);
|
||
|
|
||
|
atom.m_uds = UDS_MIME_TYPE;
|
||
|
atom.m_str = "inode/system_directory";
|
||
|
entry.append(atom);
|
||
|
}
|
||
|
|
||
|
bool VirtProtocol::lock(){
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool VirtProtocol::unlock(){
|
||
|
return true;
|
||
|
}
|