Files
qt-creator/src/libs/utils/ssh/sftpoperation.cpp

207 lines
6.0 KiB
C++
Raw Normal View History

2010-07-12 09:33:22 +02:00
/**************************************************************************
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2010-07-12 09:33:22 +02:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2010-07-12 09:33:22 +02:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2010-07-12 09:33:22 +02:00
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2010-07-12 09:33:22 +02:00
**
**************************************************************************/
#include "sftpoperation_p.h"
#include "sftpoutgoingpacket_p.h"
#include <QtCore/QFile>
namespace Utils {
2010-07-12 09:33:22 +02:00
namespace Internal {
AbstractSftpOperation::AbstractSftpOperation(SftpJobId jobId) : jobId(jobId)
{
}
AbstractSftpOperation::~AbstractSftpOperation() { }
2010-07-21 11:43:29 +02:00
SftpMakeDir::SftpMakeDir(SftpJobId jobId, const QString &path,
const SftpUploadDir::Ptr &parentJob)
: AbstractSftpOperation(jobId), parentJob(parentJob), remoteDir(path)
2010-07-12 09:33:22 +02:00
{
}
SftpOutgoingPacket &SftpMakeDir::initialPacket(SftpOutgoingPacket &packet)
{
return packet.generateMkDir(remoteDir, jobId);
}
SftpRmDir::SftpRmDir(SftpJobId, const QString &path)
: AbstractSftpOperation(jobId), remoteDir(path)
{
}
SftpOutgoingPacket &SftpRmDir::initialPacket(SftpOutgoingPacket &packet)
{
return packet.generateRmDir(remoteDir, jobId);
}
SftpRm::SftpRm(SftpJobId jobId, const QString &path)
: AbstractSftpOperation(jobId), remoteFile(path) {}
SftpOutgoingPacket &SftpRm::initialPacket(SftpOutgoingPacket &packet)
{
return packet.generateRm(remoteFile, jobId);
}
SftpRename::SftpRename(SftpJobId jobId, const QString &oldPath,
const QString &newPath)
: AbstractSftpOperation(jobId), oldPath(oldPath), newPath(newPath)
{
}
SftpOutgoingPacket &SftpRename::initialPacket(SftpOutgoingPacket &packet)
{
return packet.generateRename(oldPath, newPath, jobId);
}
AbstractSftpOperationWithHandle::AbstractSftpOperationWithHandle(SftpJobId jobId,
const QString &remotePath)
: AbstractSftpOperation(jobId),
remotePath(remotePath), state(Inactive), hasError(false)
{
}
AbstractSftpOperationWithHandle::~AbstractSftpOperationWithHandle() { }
SftpListDir::SftpListDir(SftpJobId jobId, const QString &path)
: AbstractSftpOperationWithHandle(jobId, path)
{
}
SftpOutgoingPacket &SftpListDir::initialPacket(SftpOutgoingPacket &packet)
{
state = OpenRequested;
return packet.generateOpenDir(remotePath, jobId);
}
SftpCreateFile::SftpCreateFile(SftpJobId jobId, const QString &path,
SftpOverwriteMode mode)
: AbstractSftpOperationWithHandle(jobId, path), mode(mode)
{
}
SftpOutgoingPacket & SftpCreateFile::initialPacket(SftpOutgoingPacket &packet)
{
state = OpenRequested;
return packet.generateOpenFileForWriting(remotePath, mode,
SftpOutgoingPacket::DefaultPermissions, jobId);
2010-07-12 09:33:22 +02:00
}
const int AbstractSftpTransfer::MaxInFlightCount = 10; // Experimentally found to be enough.
AbstractSftpTransfer::AbstractSftpTransfer(SftpJobId jobId, const QString &remotePath,
const QSharedPointer<QFile> &localFile)
: AbstractSftpOperationWithHandle(jobId, remotePath),
localFile(localFile), fileSize(0), offset(0), inFlightCount(0),
statRequested(false)
{
}
2010-07-21 11:43:29 +02:00
AbstractSftpTransfer::~AbstractSftpTransfer() {}
2010-07-12 09:33:22 +02:00
void AbstractSftpTransfer::calculateInFlightCount(quint32 chunkSize)
{
if (fileSize == 0) {
inFlightCount = 1;
} else {
inFlightCount = fileSize / chunkSize;
if (fileSize % chunkSize)
++inFlightCount;
if (inFlightCount > MaxInFlightCount)
inFlightCount = MaxInFlightCount;
}
}
SftpDownload::SftpDownload(SftpJobId jobId, const QString &remotePath,
const QSharedPointer<QFile> &localFile)
: AbstractSftpTransfer(jobId, remotePath, localFile), eofId(SftpInvalidJob)
{
}
SftpOutgoingPacket &SftpDownload::initialPacket(SftpOutgoingPacket &packet)
{
state = OpenRequested;
return packet.generateOpenFileForReading(remotePath, jobId);
}
2010-07-21 11:43:29 +02:00
SftpUploadFile::SftpUploadFile(SftpJobId jobId, const QString &remotePath,
const QSharedPointer<QFile> &localFile, SftpOverwriteMode mode,
const SftpUploadDir::Ptr &parentJob)
: AbstractSftpTransfer(jobId, remotePath, localFile),
parentJob(parentJob), mode(mode)
2010-07-12 09:33:22 +02:00
{
fileSize = localFile->size();
}
2010-07-21 11:43:29 +02:00
SftpOutgoingPacket &SftpUploadFile::initialPacket(SftpOutgoingPacket &packet)
2010-07-12 09:33:22 +02:00
{
state = OpenRequested;
quint32 permissions = 0;
const QFile::Permissions &qtPermissions = localFile->permissions();
if (qtPermissions & QFile::ExeOther)
permissions |= 1 << 0;
if (qtPermissions & QFile::WriteOther)
permissions |= 1 << 1;
if (qtPermissions & QFile::ReadOther)
permissions |= 1 << 2;
if (qtPermissions & QFile::ExeGroup)
permissions |= 1<< 3;
if (qtPermissions & QFile::WriteGroup)
permissions |= 1<< 4;
if (qtPermissions & QFile::ReadGroup)
permissions |= 1<< 5;
if (qtPermissions & QFile::ExeOwner)
permissions |= 1<< 6;
if (qtPermissions & QFile::WriteOwner)
permissions |= 1<< 7;
if (qtPermissions & QFile::ReadOwner)
permissions |= 1<< 8;
return packet.generateOpenFileForWriting(remotePath, mode, permissions, jobId);
2010-07-12 09:33:22 +02:00
}
2010-07-21 11:43:29 +02:00
SftpUploadDir::~SftpUploadDir() {}
2010-07-12 09:33:22 +02:00
} // namespace Internal
} // namespace Utils