RemoteLinux: Implement some of the remote file API

Implementation of remote file API for correct FilePath
work with RemoteLinux.
Added tests for this functionality

Run ssh shell in separate thread.
The linux device instance keeps its own thread for running
SshRemoteProcess. In this way all calls to filepath
interface of linux device coming from different threads
are executed in one thread (SshRemoteProcess is reentrant,
but not thread safe). The redirection to the device thread
is done by invoking SshRemoteProcess' methods through
BlockingQueuedConnection.

Done-by: Artem Sokolovskii
Change-Id: Id8756738d3a4597f175c8ef000c148d0c8536eeb
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2021-07-27 09:50:43 +02:00
committed by Artem Sokolovskii
parent 8d06519211
commit 20d19aa5bf
11 changed files with 722 additions and 39 deletions

View File

@@ -0,0 +1,141 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "filesystemaccess_test.h"
#include "linuxdevice.h"
#include "remotelinux_constants.h"
#include <utils/filepath.h>
#include <projectexplorer/devicesupport/devicemanager.h>
#include <ssh/sshconnection.h>
#include <QTest>
#include <QDebug>
using namespace ProjectExplorer;
using namespace Utils;
namespace RemoteLinux {
namespace Internal {
static const char TEST_IP[] = "127.0.0.1";
TestLinuxDeviceFactory::TestLinuxDeviceFactory()
: IDeviceFactory("test")
{
setDisplayName("Generic Linux Device");
setIcon(QIcon());
setCanCreate(true);
setConstructionFunction(&LinuxDevice::create);
}
IDevice::Ptr TestLinuxDeviceFactory::create() const
{
LinuxDevice::Ptr newDev = LinuxDevice::create();
qDebug() << "device : " << newDev->type();
newDev->setType("test");
QSsh::SshConnectionParameters sshParams = newDev->sshParameters();
sshParams.setHost(TEST_IP);
sshParams.setPort(22);
newDev->setSshParameters(sshParams);
return newDev;
}
void FileSystemAccessTest::initTestCase()
{
FilePath filePath = FilePath::fromString("ssh://"+ QString(TEST_IP) +"/tmp");
if (DeviceManager::deviceForPath(filePath) == nullptr) {
DeviceManager *const devMgr = DeviceManager::instance();
const IDevice::Ptr newDev = m_testLinuxDeviceFactory.create();
QVERIFY(!newDev.isNull());
devMgr->addDevice(newDev);
}
}
void FileSystemAccessTest::testDirStatuses()
{
FilePath filePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp");
QVERIFY(filePath.exists());
QVERIFY(filePath.isDir());
QVERIFY(filePath.isWritableDir());
FilePath testFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test");
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
dummyFilePath.copyFile(testFilePath);
QVERIFY(testFilePath.exists());
QVERIFY(testFilePath.isFile());
bool fileExists = false;
filePath.iterateDirectory(
[&fileExists](const FilePath &filePath) {
if (filePath.baseName() == "test"){
fileExists = true;
return true;
}
return false;
},
{"test"},
QDir::Files);
QVERIFY(fileExists);
QVERIFY(testFilePath.removeFile());
QVERIFY(!testFilePath.exists());
}
void FileSystemAccessTest::testFileActions()
{
FilePath testFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test");
FilePath dummyFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/dev/null");
dummyFilePath.copyFile(testFilePath);
QVERIFY(testFilePath.exists());
QVERIFY(testFilePath.isFile());
testFilePath.setPermissions(QFile::ReadOther | QFile::WriteOther | QFile::ExeOther
| QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup
| QFile::ReadUser | QFile::WriteUser | QFile::ExeUser);
QVERIFY(testFilePath.isWritableFile());
QVERIFY(testFilePath.isReadableFile());
QVERIFY(testFilePath.isExecutableFile());
QByteArray content("Test");
testFilePath.writeFileContents(content);
// ToDo: remove ".contains", make fileContents exact equal content
QVERIFY(testFilePath.fileContents().contains(content));
QVERIFY(testFilePath.renameFile(FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test1")));
// It is Ok that FilePath doesn't change itself after rename.
FilePath newTestFilePath = FilePath::fromString("ssh://" + QString(TEST_IP) + "/tmp/test1");
QVERIFY(newTestFilePath.exists());
QVERIFY(!testFilePath.removeFile());
QVERIFY(newTestFilePath.exists());
QVERIFY(newTestFilePath.removeFile());
QVERIFY(!newTestFilePath.exists());
}
} // Internal
} // RemoteLinux