Commit ebd091f3 authored by Philipp Schmidt's avatar Philipp Schmidt
Browse files

BUG: 310048 Handle copy destination for storages correctly

Fixes storages not being recognized as valid destinations when copying
to the device. Also added some more sane debug information.
parent 844f6e47
......@@ -105,6 +105,8 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
{
ret.first = device;
ret.second = device;
kDebug(KIO_MTP) << "returning LIBMTP_mtpdevice_t";
}
if ( pathItems.size() > 2 )
......@@ -122,6 +124,8 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
ret.first = file;
ret.second = device;
kDebug(KIO_MTP) << "returning LIBMTP_file_t";
return ret;
}
}
......@@ -148,6 +152,8 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
ret.first = file;
ret.second = device;
kDebug(KIO_MTP) << "returning LIBMTP_file_t";
fileCache->addPath( path, file->item_id );
}
......@@ -160,8 +166,6 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
if ( pathItems.size() > 1 && storages.contains ( pathItems.at ( 1 ) ) )
{
kDebug(KIO_MTP) << "storages!!!!!!!!!!!!!!!!!!!";
LIBMTP_devicestorage_t *storage = storages.value ( pathItems.at ( 1 ) );
if ( pathItems.size() == 2 )
......@@ -169,6 +173,8 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
ret.first = storage;
ret.second = device;
kDebug(KIO_MTP) << "returning LIBMTP_devicestorage_t";
return ret;
}
......@@ -187,6 +193,9 @@ QPair<void*, LIBMTP_mtpdevice_t*> MTPSlave::getPath ( const QString& path )
}
else
{
kDebug(KIO_MTP) << "returning LIBMTP_file_t";
return ret;
}
currentLevel++;
......@@ -700,23 +709,38 @@ void MTPSlave::copy ( const KUrl& src, const KUrl& dest, int, JobFlags flags )
}
LIBMTP_mtpdevice_t *device = pair.second;
LIBMTP_file_t *parent = ( LIBMTP_file_t* ) pair.first;
if ( parent->filetype != LIBMTP_FILETYPE_FOLDER )
uint32_t parent_id = 0xFFFFFFFF, storage_id = 0;
if ( destItems.size() == 2 )
{
error ( ERR_IS_FILE, dest.directory() );
return;
LIBMTP_devicestorage_t *storage = ( LIBMTP_devicestorage_t*) pair.first;
storage_id = storage->id;
}
else
{
LIBMTP_file_t *parent = ( LIBMTP_file_t* ) pair.first;
storage_id = parent->storage_id;
parent_id = parent->item_id;
if ( parent->filetype != LIBMTP_FILETYPE_FOLDER )
{
error ( ERR_IS_FILE, dest.directory() );
return;
}
}
QFileInfo source ( src.path() );
LIBMTP_file_t *file = LIBMTP_new_file_t();
file->parent_id = parent->item_id;
file->parent_id = parent_id;
file->filename = strdup ( dest.fileName().toUtf8().data() );
file->filetype = getFiletype ( dest.fileName() );
file->filesize = source.size();
file->modificationdate = source.lastModified().toTime_t();
file->storage_id = parent->storage_id;
file->storage_id = storage_id;
kDebug ( KIO_MTP ) << "Sending file" << file->filename << "with size" << file->filesize;
......
......@@ -41,7 +41,8 @@ int dataProgress ( uint64_t const sent, uint64_t const, void const *const priv )
*/
uint16_t dataPut ( void*, void *priv, uint32_t sendlen, unsigned char *data, uint32_t *putlen )
{
// kDebug(KIO_MTP) << "transferring" << sendlen << "bytes to data()";
kDebug(KIO_MTP) << "transferring" << sendlen << "bytes to data()";
( ( MTPSlave* ) priv )->data ( QByteArray ( ( char* ) data, ( int ) sendlen ) );
*putlen = sendlen;
......@@ -53,12 +54,16 @@ uint16_t dataPut ( void*, void *priv, uint32_t sendlen, unsigned char *data, uin
*/
uint16_t dataGet ( void*, void *priv, uint32_t, UNUSED unsigned char *data, uint32_t *gotlen )
{
// kDebug(KIO_MTP) << "transferring" << sendlen << "bytes to data()";
( ( MTPSlave* ) priv )->dataReq();
QByteArray buffer;
*gotlen = ( ( MTPSlave* ) priv )->readData ( buffer );
kDebug(KIO_MTP) << "transferring" << *gotlen << "bytes to data()";
// data = ( unsigned char* ) malloc( buffer.size() );
// memcpy( data, buffer.data(), buffer.size() );
data = ( unsigned char* ) buffer.data();
return LIBMTP_HANDLER_RETURN_OK;
......@@ -475,12 +480,14 @@ void getEntry ( UDSEntry &entry, const LIBMTP_file_t* file )
{
entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFDIR );
entry.insert ( UDSEntry::UDS_ACCESS, S_IRWXU | S_IRWXG | S_IRWXO );
entry.insert ( UDSEntry::UDS_MIME_TYPE, QLatin1String ( "inode/directory" ) );
}
else
{
entry.insert ( UDSEntry::UDS_FILE_TYPE, S_IFREG );
entry.insert ( UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH );
entry.insert ( UDSEntry::UDS_SIZE, file->filesize );
entry.insert ( UDSEntry::UDS_MIME_TYPE, getMimetype( file->filetype ) );
}
entry.insert ( UDSEntry::UDS_INODE, file->item_id );
entry.insert ( UDSEntry::UDS_ACCESS_TIME, file->modificationdate );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment