コード例 #1
0
void JobTest::copyLocalFile(const QString &src, const QString &dest)
{
    KURL u;
    u.setPath(src);
    KURL d;
    d.setPath(dest);

    // copy the file with file_copy
    bool ok = KIO::NetAccess::file_copy(u, d);
    assert(ok);
    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there

    {
        // check that the timestamp is the same (#24443)
        // Note: this only works because of copy() in kio_file.
        // The datapump solution ignores mtime, the app has to call FileCopyJob::setModificationTime()
        QFileInfo srcInfo(src);
        QFileInfo destInfo(dest);
        assert(srcInfo.lastModified() == destInfo.lastModified());
    }

    // cleanup and retry with KIO::copy()
    QFile::remove(dest);
    ok = KIO::NetAccess::dircopy(u, d, 0);
    assert(ok);
    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there
    {
        // check that the timestamp is the same (#24443)
        QFileInfo srcInfo(src);
        QFileInfo destInfo(dest);
        assert(srcInfo.lastModified() == destInfo.lastModified());
    }
}
コード例 #2
0
void JobTest::copyLocalDirectory(const QString &src, const QString &_dest, int flags)
{
    assert(QFileInfo(src).isDir());
    assert(QFileInfo(src + "/testfile").isFile());
    KURL u;
    u.setPath(src);
    QString dest(_dest);
    KURL d;
    d.setPath(dest);
    if(flags & AlreadyExists)
        assert(QFile::exists(dest));
    else
        assert(!QFile::exists(dest));

    bool ok = KIO::NetAccess::dircopy(u, d, 0);
    assert(ok);

    if(flags & AlreadyExists)
    {
        dest += "/" + u.fileName();
        // kdDebug() << "Expecting dest=" << dest << endl;
    }

    assert(QFile::exists(dest));
    assert(QFileInfo(dest).isDir());
    assert(QFileInfo(dest + "/testfile").isFile());
    assert(QFile::exists(src)); // still there
    {
        // check that the timestamp is the same (#24443)
        QFileInfo srcInfo(src);
        QFileInfo destInfo(dest);
        assert(srcInfo.lastModified() == destInfo.lastModified());
    }
}
コード例 #3
0
void FileTransferJob::doStart()
{
    description(this, i18n("Receiving file over KDE-Connect"),
        QPair<QString, QString>(i18nc("File transfer origin", "From"),
        QString(mDeviceName))
    );
    KUrl destCheck = mDestination;
    if (QFile::exists(destCheck.path())) {
        QFileInfo destInfo(destCheck.path());
        KIO::RenameDialog *dialog = new KIO::RenameDialog(0,
            i18n("Incoming file exists"),
            KUrl(mDeviceName + ":/" + destCheck.fileName()),
            destCheck,
            KIO::M_OVERWRITE,
            mSize,
            destInfo.size(),
            -1,
            destInfo.created().toTime_t(),
            -1,
            destInfo.lastModified().toTime_t()
        );
        connect(this, SIGNAL(finished(KJob*)), dialog, SLOT(deleteLater()));
        connect(dialog, SIGNAL(finished(int)), SLOT(renameDone(int)));
        dialog->show();
        return;
    }
コード例 #4
0
void JobTest::copyFileToSystem(bool resolve_local_urls)
{
    kdDebug() << k_funcinfo << resolve_local_urls << endl;
    extern KIO_EXPORT bool kio_resolve_local_urls;
    kio_resolve_local_urls = resolve_local_urls;

    const QString src = homeTmpDir() + "fileFromHome";
    createTestFile(src);
    KURL u;
    u.setPath(src);
    KURL d = systemTmpDir();
    d.addPath("fileFromHome_copied");

    kdDebug() << "copying " << u << " to " << d << endl;

    // copy the file with file_copy
    KIO::FileCopyJob *job = KIO::file_copy(u, d);
    connect(job, SIGNAL(mimetype(KIO::Job *, const QString &)), this, SLOT(slotMimetype(KIO::Job *, const QString &)));
    bool ok = KIO::NetAccess::synchronousRun(job, 0);
    assert(ok);

    QString dest = realSystemPath() + "fileFromHome_copied";

    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there

    {
        // do NOT check that the timestamp is the same.
        // It can't work with file_copy when it uses the datapump,
        // unless we use setModificationTime in the app code.
    }

    // Check mimetype
    kdDebug() << m_mimetype << endl;
    // There's no mimemagic determination in kio_file in kde3. Fixing this for kde4...
    assert(m_mimetype == "application/octet-stream");
    // assert( m_mimetype == "text/plain" );

    // cleanup and retry with KIO::copy()
    QFile::remove(dest);
    ok = KIO::NetAccess::dircopy(u, d, 0);
    assert(ok);
    assert(QFile::exists(dest));
    assert(QFile::exists(src)); // still there
    {
        // check that the timestamp is the same (#79937)
        QFileInfo srcInfo(src);
        QFileInfo destInfo(dest);
        assert(srcInfo.lastModified() == destInfo.lastModified());
    }

    // restore normal behavior
    kio_resolve_local_urls = true;
}