[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/kio_virtualfile/kioslave/file
From: Allan Sandfeld Jensen <kde () carewolf ! com>
Date: 2006-07-17 12:41:20
Message-ID: 1153140080.475082.22017.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 563379 by carewolf:
Access rights and better writing
M +42 -26 file.cc
M +1 -1 file.h
--- branches/work/kio_virtualfile/kioslave/file/file.cc #563378:563379
@@ -362,7 +362,7 @@
}
-void FileProtocol::open( const KUrl& url )
+void FileProtocol::open( const KUrl& url, int access )
{
kDebug( 7101 ) << "File::open" << endl;
@@ -385,7 +385,14 @@
return;
}
- int fd = KDE_open( _path.data(), O_RDONLY);
+ int flags = 0;
+ if (access == 1) flags = O_RDONLY;
+ else
+ if (access == 2) flags = O_WRONLY;
+ else
+ if (access == 3) flags = O_RDWR;
+
+ int fd = KDE_open( _path.data(), flags);
if ( fd < 0 ) {
error( KIO::ERR_CANNOT_OPEN_FOR_READING, url.path() );
return;
@@ -396,10 +403,10 @@
emit mimeType( mt->name() );
totalSize( buff.st_size );
-
- emit file((void*)fd);
position( 0 );
+ emit opened();
+
QByteArray array;
// Command-loop:
@@ -420,34 +427,38 @@
int bytes;
stream >> bytes;
char buffer[ bytes ];
- ::read(fd, buffer, bytes);
- array = array.fromRawData(buffer, bytes);
- data( array );
- array.clear();
+ read_retry:
+ int res = ::read(fd, buffer, bytes);
+ if (res >= 0) {
+ array = array.fromRawData(buffer, bytes);
+ data( array );
+ array.clear();
+ } else {
+ if (errno == EINTR) goto read_retry;
+ error( KIO::ERR_COULD_NOT_READ, url.path());
+ break;
+ }
continue;
}
case CMD_WRITE: {
kDebug( 7101 ) << "File::open -- write" << endl;
- QByteArray buffer;
- dataReq(); // Request for data
- int result = readData( buffer );
+ QByteArray &buffer = args;
- if (result >= 0)
+ if (write_all( fd, buffer.data(), buffer.size()))
{
- if (write_all( fd, buffer.data(), buffer.size()))
+ if ( errno == ENOSPC ) // disk full
{
- if ( errno == ENOSPC ) // disk full
- {
- error( KIO::ERR_DISK_FULL, url);
- cmd = CMD_CLOSE;
- }
- else
- {
- kWarning(7101) << "Couldn't write. Error:" << strerror(errno) << endl;
- error( KIO::ERR_COULD_NOT_WRITE, url);
- cmd = CMD_CLOSE;
- }
+ error( KIO::ERR_DISK_FULL, url.path());
+ break;
}
+ else
+ {
+ kWarning(7101) << "Couldn't write. Error:" << strerror(errno) << endl;
+ error( KIO::ERR_COULD_NOT_WRITE, url.path());
+ break;
+ }
+ } else {
+ written(buffer.size());
}
continue;
}
@@ -455,8 +466,13 @@
kDebug( 7101 ) << "File::open -- seek" << endl;
int offset;
stream >> offset;
- KDE_lseek(fd, offset, SEEK_SET);
- position( offset );
+ int res = KDE_lseek(fd, offset, SEEK_SET);
+ if (res != -1) {
+ position( offset );
+ } else {
+ error(KIO::ERR_COULD_NOT_SEEK, url.path());
+ break;
+ }
continue;
}
case CMD_NONE:
--- branches/work/kio_virtualfile/kioslave/file/file.h #563378:563379
@@ -61,7 +61,7 @@
virtual void mkdir( const KUrl& url, int permissions );
virtual void chmod( const KUrl& url, int permissions );
virtual void del( const KUrl& url, bool isfile);
- virtual void open( const KUrl& url );
+ virtual void open( const KUrl& url, int access );
/**
* Special commands supported by this slave:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic