From 472156a41b1348c714986c772759ad950fffbe75 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 15:11:21 -0600 Subject: Rename kioslaves --- tdeioslave/floppy/CMakeLists.txt | 6 +- tdeioslave/floppy/Makefile.am | 8 +- tdeioslave/floppy/floppy.protocol | 2 +- tdeioslave/floppy/kio_floppy.cpp | 1169 ------------------------------------ tdeioslave/floppy/kio_floppy.h | 78 --- tdeioslave/floppy/tdeio_floppy.cpp | 1169 ++++++++++++++++++++++++++++++++++++ tdeioslave/floppy/tdeio_floppy.h | 78 +++ 7 files changed, 1255 insertions(+), 1255 deletions(-) delete mode 100644 tdeioslave/floppy/kio_floppy.cpp delete mode 100644 tdeioslave/floppy/kio_floppy.h create mode 100644 tdeioslave/floppy/tdeio_floppy.cpp create mode 100644 tdeioslave/floppy/tdeio_floppy.h (limited to 'tdeioslave/floppy') diff --git a/tdeioslave/floppy/CMakeLists.txt b/tdeioslave/floppy/CMakeLists.txt index b328998ab..3ce6ffe01 100644 --- a/tdeioslave/floppy/CMakeLists.txt +++ b/tdeioslave/floppy/CMakeLists.txt @@ -26,12 +26,12 @@ link_directories( install( FILES floppy.protocol DESTINATION ${SERVICES_INSTALL_DIR} ) -##### kio_floppy (module) ####################### +##### tdeio_floppy (module) ####################### -set( target kio_floppy ) +set( target tdeio_floppy ) set( ${target}_SRCS - kio_floppy.cpp program.cpp + tdeio_floppy.cpp program.cpp ) tde_add_kpart( ${target} AUTOMOC diff --git a/tdeioslave/floppy/Makefile.am b/tdeioslave/floppy/Makefile.am index ec422f75d..e6b52fe17 100644 --- a/tdeioslave/floppy/Makefile.am +++ b/tdeioslave/floppy/Makefile.am @@ -5,11 +5,11 @@ AM_LDFLAGS = $(all_libraries) ####### Files -kde_module_LTLIBRARIES = kio_floppy.la +kde_module_LTLIBRARIES = tdeio_floppy.la -kio_floppy_la_SOURCES = kio_floppy.cpp program.cpp -kio_floppy_la_LIBADD = $(LIB_KIO) -kio_floppy_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +tdeio_floppy_la_SOURCES = tdeio_floppy.cpp program.cpp +tdeio_floppy_la_LIBADD = $(LIB_KIO) +tdeio_floppy_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) kdelnk_DATA = floppy.protocol kdelnkdir = $(kde_servicesdir) diff --git a/tdeioslave/floppy/floppy.protocol b/tdeioslave/floppy/floppy.protocol index af861d1be..84a1b12b8 100644 --- a/tdeioslave/floppy/floppy.protocol +++ b/tdeioslave/floppy/floppy.protocol @@ -1,5 +1,5 @@ [Protocol] -exec=kio_floppy +exec=tdeio_floppy protocol=floppy input=none output=filesystem diff --git a/tdeioslave/floppy/kio_floppy.cpp b/tdeioslave/floppy/kio_floppy.cpp deleted file mode 100644 index 626a4a1f0..000000000 --- a/tdeioslave/floppy/kio_floppy.cpp +++ /dev/null @@ -1,1169 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2000 Alexander Neundorf - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_STRING_H -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "kio_floppy.h" - -#include -#include -#include -#include - -using namespace TDEIO; - -extern "C" { KDE_EXPORT int kdemain(int argc, char **argv); } - -int kdemain( int argc, char **argv ) -{ - TDEInstance instance( "kio_floppy" ); - - if (argc != 4) - { - fprintf(stderr, "Usage: kio_floppy protocol domain-socket1 domain-socket2\n"); - exit(-1); - } - kdDebug(7101) << "Floppy: kdemain: starting" << endl; - - FloppyProtocol slave(argv[2], argv[3]); - slave.dispatchLoop(); - return 0; -} - -void getDriveAndPath(const TQString& path, TQString& drive, TQString& rest) -{ - drive=TQString::null; - rest=TQString::null; - TQStringList list=TQStringList::split("/",path); - for (TQStringList::Iterator it=list.begin(); it!=list.end(); it++) - { - if (it==list.begin()) - drive=(*it)+":"; - else - rest=rest+"/"+(*it); - } -} - -FloppyProtocol::FloppyProtocol (const TQCString &pool, const TQCString &app ) -:SlaveBase( "floppy", pool, app ) -,m_mtool(0) -,m_stdoutBuffer(0) -,m_stderrBuffer(0) -,m_stdoutSize(0) -,m_stderrSize(0) -{ - kdDebug(7101)<<"Floppy::Floppy: -"<stdoutFD(),buffer,16*1024); - if (length<=0) return 0; - - //+1 gives us room for a terminating 0 - char *newBuffer=new char[length+m_stdoutSize+1]; - kdDebug(7101)<<"Floppy::readStdout(): length: "<stderrFD(),buffer,16*1024); - kdDebug(7101)<<"Floppy::readStderr(): read "< -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access drive %1.\nThe drive is still busy.\nWait until it is inactive and then try again.").arg(drive)); - } - else if ((line.find("Disk full") > -1) || (line.find("No free cluster") > -1)) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not write to file %1.\nThe disk in drive %2 is probably full.").arg(url.prettyURL(),drive)); - } - //file not found - else if (line.find("not found") > -1) - { - error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL()); - } - //no disk - else if (line.find("not configured") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThere is probably no disk in the drive %2").arg(url.prettyURL(),drive)); - } - else if (line.find("No such device") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThere is probably no disk in the drive %2 or you do not have enough permissions to access the drive.").arg(url.prettyURL(),drive)); - } - else if (line.find("not supported") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThe drive %2 is not supported.").arg(url.prettyURL(),drive)); - } - //not supported or no such drive - else if (line.find("Permission denied") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nMake sure the floppy in drive %2 is a DOS-formatted floppy disk \nand that the permissions of the device file (e.g. /dev/fd0) are set correctly (e.g. rwxrwxrwx).").arg(url.prettyURL(),drive)); - } - else if (line.find("non DOS media") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThe disk in drive %2 is probably not a DOS-formatted floppy disk.").arg(url.prettyURL(),drive)); - } - else if (line.find("Read-only") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Access denied.\nCould not write to %1.\nThe disk in drive %2 is probably write-protected.").arg(url.prettyURL(),drive)); - } - else if ((outputString.find("already exists") > -1) || (outputString.find("Skipping ") > -1)) - { - error( TDEIO::ERR_FILE_ALREADY_EXIST,url.prettyURL()); - //return false; - } - else if (outputString.find("could not read boot sector") > -1) - { - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not read boot sector for %1.\nThere is probably not any disk in drive %2.").arg(url.prettyURL(),drive)); - //return false; - } - else - { - error( TDEIO::ERR_UNKNOWN, outputString); - } - return true; -} - -void FloppyProtocol::listDir( const KURL& _url) -{ - kdDebug(7101)<<"Floppy::listDir() "<<_url.path()<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mdir"); - return; - } - - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(url,drive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - delete m_mtool; - m_mtool=0; - //now mdir has finished - //let's parse the output - terminateBuffers(); - - if (errorOccured) - return; - - TQString outputString(m_stdoutBuffer); - TQTextIStream output(&outputString); - TQString line; - - int totalNumber(0); - int mode(0); - UDSEntry entry; - - while (!output.atEnd()) - { - line=output.readLine(); - kdDebug(7101)<<"Floppy::listDir(): line: -"<0) - { - name=line.mid(0,nameLength); - TQString ext=line.mid(9,3); - ext=ext.stripWhiteSpace(); - if (!ext.isEmpty()) - name+="."+ext; - } - kdDebug(7101)<<"Floppy::createStatInfo() name 8.3= -"<41) - { - name=line.mid(42); - kdDebug(7101)<<"Floppy::createStatInfo() name vfat: -"<") - { - //kdDebug(7101)<<"Floppy::createUDSEntry() isDir"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mdir"); - return info; - } - - - clearBuffers(); - - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(url,drive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - //kdDebug(7101)<<"Floppy::_stat(): delete m_mtool"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mdir"); - return -1; - } - - - clearBuffers(); - - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(url,drive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - //kdDebug(7101)<<"Floppy::freeSpace(): delete m_mtool"<_stat(url); - if (info.isValid) - { - UDSEntry entry; - createUDSEntry(info,entry); - statEntry( entry ); - finished(); - //kdDebug(7101)<<"Floppy::stat(): ends"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mmd"); - return; - } - - - clearBuffers(); - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(url,drive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - delete m_mtool; - m_mtool=0; - terminateBuffers(); - if (errorOccured) - return; - finished(); -} - -void FloppyProtocol::del( const KURL& url, bool isfile) -{ - kdDebug(7101)<<"FloppyProtocol::del()"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram(usingmdel ? TQString("mdel") : TQString("mrd")); - return; - } - - - clearBuffers(); - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(url,drive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - delete m_mtool; - m_mtool=0; - terminateBuffers(); - if (errorOccured) - return; - finished(); -} - -void FloppyProtocol::rename( const KURL &src, const KURL &dest, bool _overwrite ) -{ - TQString srcPath(src.path()); - TQString destPath(dest.path()); - - kdDebug(7101)<<"Floppy::rename() -"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mren"); - return; - } - - - clearBuffers(); - int result; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - if (readStdout()==0) - loopFinished=true; - if (stderrEvent) - { - if (readStderr()==0) - loopFinished=true; - else - if (stopAfterError(src,srcDrive)) - { - loopFinished=true; - errorOccured=true; - } - } - } while (!loopFinished); - - delete m_mtool; - m_mtool=0; - terminateBuffers(); - if (errorOccured) - return; - finished(); -} - -void FloppyProtocol::get( const KURL& url ) -{ - TQString path(url.path()); - kdDebug(7101)<<"Floppy::get() -"<_stat(url); - //the error was already reported in _stat() - if (info.isValid==false) - return; - - totalSize( info.size); - - TQString drive; - TQString floppyPath; - getDriveAndPath(path,drive,floppyPath); - if (floppyPath.isEmpty()) - { - finished(); - return; - } - - if (m_mtool!=0) - delete m_mtool; - //kdDebug(7101)<<"Floppy::stat(): create args"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mcopy"); - return; - } - - clearBuffers(); - int result; - int bytesRead(0); - TQByteArray array; - bool loopFinished(false); - bool errorOccured(false); - do - { - bool stdoutEvent; - bool stderrEvent; - result=m_mtool->select(1,0,stdoutEvent, stderrEvent); - if (stdoutEvent) - { - delete [] m_stdoutBuffer; - m_stdoutBuffer=0; - m_stdoutSize=0; - if (readStdout()>0) - { - kdDebug(7101)<<"Floppy::get(): m_stdoutSize:"<start()) - { - delete m_mtool; - m_mtool=0; - errorMissingMToolsProgram("mcopy"); - return; - } - - - clearBuffers(); - int result(0); - int bytesRead(0); - TQByteArray array; - - //from file.cc - // Loop until we got 0 (end of data) - do - { - bool stdoutEvent; - bool stderrEvent; - kdDebug(7101)<<"Floppy::put(): select()..."<select(0,100,stdoutEvent, stderrEvent); - if (stdoutEvent) - { - if (readStdout()==0) - result=0; - } - if (stderrEvent) - { - if (readStderr()==0) - result=0; - else - if (stopAfterError(url,drive)) - result=-1; - kdDebug(7101)<<"Floppy::put(): error: result=="< 0) - { - bytesRead+=result; - kdDebug(7101)<<"Floppy::put() bytesRead: "<freeSpaceLeft) - { - result=0; - error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not write to file %1.\nThe disk in drive %2 is probably full.").arg(url.prettyURL(),drive)); - } - else - { - //kdDebug(7101)<<"Floppy::put(): writing..."<stdinFD(),buffer.data(), buffer.size()); - kdDebug(7101)<<"Floppy::put(): after write(), wrote "< 0 ); - - if (result<0) - { - perror("writing to stdin"); - error( TDEIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyURL()); - return; - } - - delete m_mtool; - m_mtool=0; - - finished(); -} - diff --git a/tdeioslave/floppy/kio_floppy.h b/tdeioslave/floppy/kio_floppy.h deleted file mode 100644 index d38340729..000000000 --- a/tdeioslave/floppy/kio_floppy.h +++ /dev/null @@ -1,78 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000 Alexander Neundorf - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KIO_FLOPPY_H -#define KIO_FLOPPY_H - -#include -#include - -#include "program.h" - -#include - -struct StatInfo -{ - StatInfo():name(""),time(0),size(0),mode(0),freeSpace(0),isDir(false),isValid(false) {;} - TQString name; - time_t time; - int size; - int mode; - int freeSpace; - bool isDir:1; - bool isValid:1; -}; - - -class FloppyProtocol : public TDEIO::SlaveBase -{ - public: - FloppyProtocol (const TQCString &pool, const TQCString &app ); - virtual ~FloppyProtocol(); - - virtual void listDir( const KURL& url); - virtual void stat( const KURL & url); - virtual void mkdir( const KURL& url, int); - virtual void del( const KURL& url, bool isfile); - virtual void rename(const KURL &src, const KURL &dest, bool overwrite); - virtual void get( const KURL& url ); - virtual void put( const KURL& url, int _mode,bool overwrite, bool _resume ); - //virtual void copy( const KURL& src, const KURL &dest, int, bool overwrite ); - protected: - Program *m_mtool; - int readStdout(); - int readStderr(); - - StatInfo createStatInfo(const TQString line, bool makeStat=false, const TQString& dirName=""); - void createUDSEntry(const StatInfo& info, TDEIO::UDSEntry& entry); - StatInfo _stat(const KURL& _url); - int freeSpace(const KURL& url); - - bool stopAfterError(const KURL& url, const TQString& drive); - void errorMissingMToolsProgram(const TQString& name); - - void clearBuffers(); - void terminateBuffers(); - char *m_stdoutBuffer; - char *m_stderrBuffer; - int m_stdoutSize; - int m_stderrSize; -}; - -#endif diff --git a/tdeioslave/floppy/tdeio_floppy.cpp b/tdeioslave/floppy/tdeio_floppy.cpp new file mode 100644 index 000000000..0e576e472 --- /dev/null +++ b/tdeioslave/floppy/tdeio_floppy.cpp @@ -0,0 +1,1169 @@ +/* This file is part of the KDE project + + Copyright (C) 2000 Alexander Neundorf + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tdeio_floppy.h" + +#include +#include +#include +#include + +using namespace TDEIO; + +extern "C" { KDE_EXPORT int kdemain(int argc, char **argv); } + +int kdemain( int argc, char **argv ) +{ + TDEInstance instance( "tdeio_floppy" ); + + if (argc != 4) + { + fprintf(stderr, "Usage: tdeio_floppy protocol domain-socket1 domain-socket2\n"); + exit(-1); + } + kdDebug(7101) << "Floppy: kdemain: starting" << endl; + + FloppyProtocol slave(argv[2], argv[3]); + slave.dispatchLoop(); + return 0; +} + +void getDriveAndPath(const TQString& path, TQString& drive, TQString& rest) +{ + drive=TQString::null; + rest=TQString::null; + TQStringList list=TQStringList::split("/",path); + for (TQStringList::Iterator it=list.begin(); it!=list.end(); it++) + { + if (it==list.begin()) + drive=(*it)+":"; + else + rest=rest+"/"+(*it); + } +} + +FloppyProtocol::FloppyProtocol (const TQCString &pool, const TQCString &app ) +:SlaveBase( "floppy", pool, app ) +,m_mtool(0) +,m_stdoutBuffer(0) +,m_stderrBuffer(0) +,m_stdoutSize(0) +,m_stderrSize(0) +{ + kdDebug(7101)<<"Floppy::Floppy: -"<stdoutFD(),buffer,16*1024); + if (length<=0) return 0; + + //+1 gives us room for a terminating 0 + char *newBuffer=new char[length+m_stdoutSize+1]; + kdDebug(7101)<<"Floppy::readStdout(): length: "<stderrFD(),buffer,16*1024); + kdDebug(7101)<<"Floppy::readStderr(): read "< -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access drive %1.\nThe drive is still busy.\nWait until it is inactive and then try again.").arg(drive)); + } + else if ((line.find("Disk full") > -1) || (line.find("No free cluster") > -1)) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not write to file %1.\nThe disk in drive %2 is probably full.").arg(url.prettyURL(),drive)); + } + //file not found + else if (line.find("not found") > -1) + { + error( TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL()); + } + //no disk + else if (line.find("not configured") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThere is probably no disk in the drive %2").arg(url.prettyURL(),drive)); + } + else if (line.find("No such device") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThere is probably no disk in the drive %2 or you do not have enough permissions to access the drive.").arg(url.prettyURL(),drive)); + } + else if (line.find("not supported") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThe drive %2 is not supported.").arg(url.prettyURL(),drive)); + } + //not supported or no such drive + else if (line.find("Permission denied") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nMake sure the floppy in drive %2 is a DOS-formatted floppy disk \nand that the permissions of the device file (e.g. /dev/fd0) are set correctly (e.g. rwxrwxrwx).").arg(url.prettyURL(),drive)); + } + else if (line.find("non DOS media") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not access %1.\nThe disk in drive %2 is probably not a DOS-formatted floppy disk.").arg(url.prettyURL(),drive)); + } + else if (line.find("Read-only") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Access denied.\nCould not write to %1.\nThe disk in drive %2 is probably write-protected.").arg(url.prettyURL(),drive)); + } + else if ((outputString.find("already exists") > -1) || (outputString.find("Skipping ") > -1)) + { + error( TDEIO::ERR_FILE_ALREADY_EXIST,url.prettyURL()); + //return false; + } + else if (outputString.find("could not read boot sector") > -1) + { + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not read boot sector for %1.\nThere is probably not any disk in drive %2.").arg(url.prettyURL(),drive)); + //return false; + } + else + { + error( TDEIO::ERR_UNKNOWN, outputString); + } + return true; +} + +void FloppyProtocol::listDir( const KURL& _url) +{ + kdDebug(7101)<<"Floppy::listDir() "<<_url.path()<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mdir"); + return; + } + + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(url,drive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + delete m_mtool; + m_mtool=0; + //now mdir has finished + //let's parse the output + terminateBuffers(); + + if (errorOccured) + return; + + TQString outputString(m_stdoutBuffer); + TQTextIStream output(&outputString); + TQString line; + + int totalNumber(0); + int mode(0); + UDSEntry entry; + + while (!output.atEnd()) + { + line=output.readLine(); + kdDebug(7101)<<"Floppy::listDir(): line: -"<0) + { + name=line.mid(0,nameLength); + TQString ext=line.mid(9,3); + ext=ext.stripWhiteSpace(); + if (!ext.isEmpty()) + name+="."+ext; + } + kdDebug(7101)<<"Floppy::createStatInfo() name 8.3= -"<41) + { + name=line.mid(42); + kdDebug(7101)<<"Floppy::createStatInfo() name vfat: -"<") + { + //kdDebug(7101)<<"Floppy::createUDSEntry() isDir"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mdir"); + return info; + } + + + clearBuffers(); + + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(url,drive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + //kdDebug(7101)<<"Floppy::_stat(): delete m_mtool"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mdir"); + return -1; + } + + + clearBuffers(); + + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(url,drive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + //kdDebug(7101)<<"Floppy::freeSpace(): delete m_mtool"<_stat(url); + if (info.isValid) + { + UDSEntry entry; + createUDSEntry(info,entry); + statEntry( entry ); + finished(); + //kdDebug(7101)<<"Floppy::stat(): ends"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mmd"); + return; + } + + + clearBuffers(); + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(url,drive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + delete m_mtool; + m_mtool=0; + terminateBuffers(); + if (errorOccured) + return; + finished(); +} + +void FloppyProtocol::del( const KURL& url, bool isfile) +{ + kdDebug(7101)<<"FloppyProtocol::del()"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram(usingmdel ? TQString("mdel") : TQString("mrd")); + return; + } + + + clearBuffers(); + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(url,drive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + delete m_mtool; + m_mtool=0; + terminateBuffers(); + if (errorOccured) + return; + finished(); +} + +void FloppyProtocol::rename( const KURL &src, const KURL &dest, bool _overwrite ) +{ + TQString srcPath(src.path()); + TQString destPath(dest.path()); + + kdDebug(7101)<<"Floppy::rename() -"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mren"); + return; + } + + + clearBuffers(); + int result; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + if (readStdout()==0) + loopFinished=true; + if (stderrEvent) + { + if (readStderr()==0) + loopFinished=true; + else + if (stopAfterError(src,srcDrive)) + { + loopFinished=true; + errorOccured=true; + } + } + } while (!loopFinished); + + delete m_mtool; + m_mtool=0; + terminateBuffers(); + if (errorOccured) + return; + finished(); +} + +void FloppyProtocol::get( const KURL& url ) +{ + TQString path(url.path()); + kdDebug(7101)<<"Floppy::get() -"<_stat(url); + //the error was already reported in _stat() + if (info.isValid==false) + return; + + totalSize( info.size); + + TQString drive; + TQString floppyPath; + getDriveAndPath(path,drive,floppyPath); + if (floppyPath.isEmpty()) + { + finished(); + return; + } + + if (m_mtool!=0) + delete m_mtool; + //kdDebug(7101)<<"Floppy::stat(): create args"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mcopy"); + return; + } + + clearBuffers(); + int result; + int bytesRead(0); + TQByteArray array; + bool loopFinished(false); + bool errorOccured(false); + do + { + bool stdoutEvent; + bool stderrEvent; + result=m_mtool->select(1,0,stdoutEvent, stderrEvent); + if (stdoutEvent) + { + delete [] m_stdoutBuffer; + m_stdoutBuffer=0; + m_stdoutSize=0; + if (readStdout()>0) + { + kdDebug(7101)<<"Floppy::get(): m_stdoutSize:"<start()) + { + delete m_mtool; + m_mtool=0; + errorMissingMToolsProgram("mcopy"); + return; + } + + + clearBuffers(); + int result(0); + int bytesRead(0); + TQByteArray array; + + //from file.cc + // Loop until we got 0 (end of data) + do + { + bool stdoutEvent; + bool stderrEvent; + kdDebug(7101)<<"Floppy::put(): select()..."<select(0,100,stdoutEvent, stderrEvent); + if (stdoutEvent) + { + if (readStdout()==0) + result=0; + } + if (stderrEvent) + { + if (readStderr()==0) + result=0; + else + if (stopAfterError(url,drive)) + result=-1; + kdDebug(7101)<<"Floppy::put(): error: result=="< 0) + { + bytesRead+=result; + kdDebug(7101)<<"Floppy::put() bytesRead: "<freeSpaceLeft) + { + result=0; + error( TDEIO::ERR_SLAVE_DEFINED, i18n("Could not write to file %1.\nThe disk in drive %2 is probably full.").arg(url.prettyURL(),drive)); + } + else + { + //kdDebug(7101)<<"Floppy::put(): writing..."<stdinFD(),buffer.data(), buffer.size()); + kdDebug(7101)<<"Floppy::put(): after write(), wrote "< 0 ); + + if (result<0) + { + perror("writing to stdin"); + error( TDEIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyURL()); + return; + } + + delete m_mtool; + m_mtool=0; + + finished(); +} + diff --git a/tdeioslave/floppy/tdeio_floppy.h b/tdeioslave/floppy/tdeio_floppy.h new file mode 100644 index 000000000..d38340729 --- /dev/null +++ b/tdeioslave/floppy/tdeio_floppy.h @@ -0,0 +1,78 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Alexander Neundorf + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KIO_FLOPPY_H +#define KIO_FLOPPY_H + +#include +#include + +#include "program.h" + +#include + +struct StatInfo +{ + StatInfo():name(""),time(0),size(0),mode(0),freeSpace(0),isDir(false),isValid(false) {;} + TQString name; + time_t time; + int size; + int mode; + int freeSpace; + bool isDir:1; + bool isValid:1; +}; + + +class FloppyProtocol : public TDEIO::SlaveBase +{ + public: + FloppyProtocol (const TQCString &pool, const TQCString &app ); + virtual ~FloppyProtocol(); + + virtual void listDir( const KURL& url); + virtual void stat( const KURL & url); + virtual void mkdir( const KURL& url, int); + virtual void del( const KURL& url, bool isfile); + virtual void rename(const KURL &src, const KURL &dest, bool overwrite); + virtual void get( const KURL& url ); + virtual void put( const KURL& url, int _mode,bool overwrite, bool _resume ); + //virtual void copy( const KURL& src, const KURL &dest, int, bool overwrite ); + protected: + Program *m_mtool; + int readStdout(); + int readStderr(); + + StatInfo createStatInfo(const TQString line, bool makeStat=false, const TQString& dirName=""); + void createUDSEntry(const StatInfo& info, TDEIO::UDSEntry& entry); + StatInfo _stat(const KURL& _url); + int freeSpace(const KURL& url); + + bool stopAfterError(const KURL& url, const TQString& drive); + void errorMissingMToolsProgram(const TQString& name); + + void clearBuffers(); + void terminateBuffers(); + char *m_stdoutBuffer; + char *m_stderrBuffer; + int m_stdoutSize; + int m_stderrSize; +}; + +#endif -- cgit v1.2.3