Exemplo n.º 1
0
TEST(Templates, CopyOrMove) {
    auto shared = std::make_shared<int>(42);
    auto shared_cpy = copyOrMove(shared);
    EXPECT_EQ(shared, shared_cpy);
    auto unique = std::unique_ptr<int>(new int{42});
    auto unique_mvd = copyOrMove(unique);
    EXPECT_FALSE(unique);
    EXPECT_EQ(42, *unique_mvd);
}
Exemplo n.º 2
0
void TrashProtocol::restore( const KUrl& trashURL )
{
    int trashId;
    QString fileId, relativePath;
    bool ok = TrashImpl::parseURL( trashURL, trashId, fileId, relativePath );
    if ( !ok ) {
        error( KIO::ERR_SLAVE_DEFINED, i18n( "Malformed URL %1", trashURL.prettyUrl() ) );
        return;
    }
    TrashedFileInfo info;
    ok = impl.infoForFile( trashId, fileId, info );
    if ( !ok ) {
        error( impl.lastErrorCode(), impl.lastErrorMessage() );
        return;
    }
    KUrl dest;
    dest.setPath( info.origPath );
    if ( !relativePath.isEmpty() )
        dest.addPath( relativePath );

    // Check that the destination directory exists, to improve the error code in case it doesn't.
    const QString destDir = dest.directory();
    KDE_struct_stat buff;
    if ( KDE_lstat( QFile::encodeName( destDir ), &buff ) == -1 ) {
        error( KIO::ERR_SLAVE_DEFINED,
               i18n( "The directory %1 does not exist anymore, so it is not possible to restore this item to its original location. "
                     "You can either recreate that directory and use the restore operation again, or drag the item anywhere else to restore it.", destDir ) );
        return;
    }

    copyOrMove( trashURL, dest, false /*overwrite*/, Move );
}
Exemplo n.º 3
0
void TrashProtocol::copy( const KUrl &src, const KUrl &dest, int /*permissions*/, KIO::JobFlags flags )
{
    INIT_IMPL;

    kDebug()<<"TrashProtocol::copy(): " << src << " " << dest;

    if (src.protocol() == QLatin1String("trash") && dest.protocol() == QLatin1String("trash")) {
        error( KIO::ERR_UNSUPPORTED_ACTION, i18n( "This file is already in the trash bin." ) );
        return;
    }

    copyOrMove( src, dest, (flags & KIO::Overwrite), Copy );
}
Exemplo n.º 4
0
void TrashProtocol::rename( const KUrl &oldURL, const KUrl &newURL, KIO::JobFlags flags )
{
    INIT_IMPL;

    kDebug()<<"TrashProtocol::rename(): old="<<oldURL<<" new="<<newURL<<" overwrite=" << (flags & KIO::Overwrite);

    if (oldURL.protocol() == QLatin1String("trash") && newURL.protocol() == QLatin1String("trash")) {
        error( KIO::ERR_CANNOT_RENAME, oldURL.prettyUrl() );
        return;
    }

    copyOrMove( oldURL, newURL, (flags & KIO::Overwrite), Move );
}
Exemplo n.º 5
0
void TrashProtocol::copy(const KURL &src, const KURL &dest, int /*permissions*/, bool overwrite)
{
    INIT_IMPL;

    kdDebug() << "TrashProtocol::copy(): " << src << " " << dest << endl;

    if(src.protocol() == "trash" && dest.protocol() == "trash")
    {
        error(KIO::ERR_UNSUPPORTED_ACTION, i18n("This file is already in the trash bin."));
        return;
    }

    copyOrMove(src, dest, overwrite, Copy);
}
Exemplo n.º 6
0
void TrashProtocol::rename(const KURL &oldURL, const KURL &newURL, bool overwrite)
{
    INIT_IMPL;

    kdDebug() << "TrashProtocol::rename(): old=" << oldURL << " new=" << newURL << " overwrite=" << overwrite << endl;

    if(oldURL.protocol() == "trash" && newURL.protocol() == "trash")
    {
        error(KIO::ERR_CANNOT_RENAME, oldURL.prettyURL());
        return;
    }

    copyOrMove(oldURL, newURL, overwrite, Move);
}
/*
 * Starts the operation.
 * \a isStopped flag the outside stop operation
 */
void FmOperationCopyOrMove::start( volatile bool *isStopped )
{
    mStop = isStopped; 
    mTotalSize   = 0;
    mCopiedOrMovedSize  = 0;
    mCurrentStep = 0;

    if ( mSourceList.empty() ) {
        emit notifyError( FmErrWrongParam, mErrString );    
        return ;
    }
	emit notifyPreparing( true );

    int numofFolders = 0;
    int numofFiles      = 0;

    int ret = FmFolderDetails::queryDetailOfContentList( mSourceList, numofFolders, 
        numofFiles, mTotalSize, mStop, true );
    if( ret != FmErrNone ) {
        emit notifyError( ret, mErrString );
        return;        
    }    
    if ( !targetHasEnoughSpace() ) {
        emit notifyError( FmErrDiskFull, mErrString );
        return;
        }    
    emit notifyStart( true, mTotalSteps );

    foreach( const QString& source, mSourceList ) {
        // formatPath, but do not append splash in the end
        // Otherwise could not get fileName in QFileInfo::fileName
        QString checkedSource( FmUtils::formatPath( source ) );
        QFileInfo fi( checkedSource );
        if( !fi.exists() ) {
            mErrString = checkedSource;   
            emit driveSpaceChanged();
            emit notifyError( FmErrSrcPathDoNotExist, mErrString );
            return;
        }
        QString newName;
        bool    isAcceptReplace = false;
        QFileInfo destFi( mTargetPath + fi.fileName() );

        // while for duplicated file/dir
        while( destFi.exists() ) {
            if( destFi.isFile() && destFi.absoluteFilePath().compare( fi.absoluteFilePath(), Qt::CaseInsensitive ) != 0 ) {
                emit askForReplace( destFi.absoluteFilePath(), fi.absoluteFilePath(), &isAcceptReplace );
                if( isAcceptReplace ) {
                    //delete src file
                    if( !QFile::remove( destFi.absoluteFilePath() ) ) {
                        mErrString = destFi.absoluteFilePath();
                        ret = FmErrCannotRemove;
                        break;
                    }
                    destFi.setFile( destFi.absoluteFilePath() );
                } else {
                    queryForRename( destFi.absoluteFilePath(), &newName );
                    if( newName.isEmpty() ) {
                        ret = FmErrCancel;
                        break;
                    }
                    QString targetName = mTargetPath + newName;
                    destFi.setFile( targetName );
                }
            } else{
                // destination is dir
                queryForRename( destFi.absoluteFilePath(), &newName );
                if( newName.isEmpty() ) {
                    ret = FmErrCancel;
                    break;
                }
                QString targetName = mTargetPath + newName;
                destFi.setFile( targetName );
            }
        }
        if( ret != FmErrNone ) {
            // refresh drive space no care if cancel, error or finished.
            // as filemanger cannot notify drive space changed
            // do not refresh path as QFileSystemModel will do auto-refresh
            emit driveSpaceChanged();
            emit notifyError( ret, mErrString );
            return;
        }
        ret = copyOrMove( checkedSource, mTargetPath, newName );
        if( ret != FmErrNone ) {
            emit driveSpaceChanged();
            emit notifyError( ret, mErrString );            
            return;
        }
    }