forked from qt-creator/qt-creator
Replace a few expected_str<void> by Utils::Result
Change-Id: I160c4dea583958e4cf55ff4de5b9f9c4937ac07f Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -1311,7 +1311,7 @@ expected_str<QString> DockManager::cloneWorkspace(const QString &originalFileNam
|
|||||||
|
|
||||||
const FilePath clonePath = workspaceNameToFilePath(cloneName);
|
const FilePath clonePath = workspaceNameToFilePath(cloneName);
|
||||||
|
|
||||||
const expected_str<void> copyResult = originalPath.copyFile(clonePath);
|
const Result copyResult = originalPath.copyFile(clonePath);
|
||||||
if (!copyResult)
|
if (!copyResult)
|
||||||
return make_unexpected(Tr::tr("Could not clone \"%1\" due to: %2")
|
return make_unexpected(Tr::tr("Could not clone \"%1\" due to: %2")
|
||||||
.arg(originalPath.toUserOutput(), copyResult.error()));
|
.arg(originalPath.toUserOutput(), copyResult.error()));
|
||||||
@@ -1337,21 +1337,21 @@ expected_str<QString> DockManager::renameWorkspace(const QString &originalFileNa
|
|||||||
return originalFileName;
|
return originalFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DockManager::resetWorkspacePreset(const QString &fileName)
|
Result DockManager::resetWorkspacePreset(const QString &fileName)
|
||||||
{
|
{
|
||||||
qCInfo(adsLog) << "Reset workspace" << fileName;
|
qCInfo(adsLog) << "Reset workspace" << fileName;
|
||||||
|
|
||||||
Workspace *w = workspace(fileName);
|
Workspace *w = workspace(fileName);
|
||||||
if (!w)
|
if (!w)
|
||||||
return make_unexpected(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName));
|
return Result::Error(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName));
|
||||||
|
|
||||||
if (!w->isPreset())
|
if (!w->isPreset())
|
||||||
return make_unexpected(Tr::tr("Workspace \"%1\" is not a preset.").arg(fileName));
|
return Result::Error(Tr::tr("Workspace \"%1\" is not a preset.").arg(fileName));
|
||||||
|
|
||||||
const FilePath filePath = w->filePath();
|
const FilePath filePath = w->filePath();
|
||||||
|
|
||||||
if (!filePath.removeFile())
|
if (!filePath.removeFile())
|
||||||
return make_unexpected(Tr::tr("Cannot remove \"%1\".").arg(filePath.toUserOutput()));
|
return Result::Error(Tr::tr("Cannot remove \"%1\".").arg(filePath.toUserOutput()));
|
||||||
|
|
||||||
return presetDirectory().pathAppended(fileName).copyFile(filePath);
|
return presetDirectory().pathAppended(fileName).copyFile(filePath);
|
||||||
}
|
}
|
||||||
@@ -1400,7 +1400,7 @@ expected_str<QString> DockManager::importWorkspace(const QString &filePath)
|
|||||||
|
|
||||||
const FilePath targetFilePath = userDirectory().pathAppended(fileName);
|
const FilePath targetFilePath = userDirectory().pathAppended(fileName);
|
||||||
|
|
||||||
const expected_str<void> copyResult = sourceFilePath.copyFile(targetFilePath);
|
const Result copyResult = sourceFilePath.copyFile(targetFilePath);
|
||||||
if (!copyResult)
|
if (!copyResult)
|
||||||
return make_unexpected(
|
return make_unexpected(
|
||||||
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
|
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
|
||||||
@@ -1441,7 +1441,7 @@ expected_str<QString> DockManager::exportWorkspace(const QString &targetFilePath
|
|||||||
Tr::tr("The workspace \"%1\" does not exist ").arg(workspaceFile.toUserOutput()));
|
Tr::tr("The workspace \"%1\" does not exist ").arg(workspaceFile.toUserOutput()));
|
||||||
|
|
||||||
// Finally copy the workspace to the target
|
// Finally copy the workspace to the target
|
||||||
const expected_str<void> copyResult = workspaceFile.copyFile(targetFile);
|
const Result copyResult = workspaceFile.copyFile(targetFile);
|
||||||
if (!copyResult)
|
if (!copyResult)
|
||||||
return make_unexpected(
|
return make_unexpected(
|
||||||
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
|
Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3")
|
||||||
@@ -1675,7 +1675,7 @@ void DockManager::syncWorkspacePresets()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const expected_str<void> copyResult = filePath.copyFile(
|
const Result copyResult = filePath.copyFile(
|
||||||
userDirectory().pathAppended(filePath.fileName()));
|
userDirectory().pathAppended(filePath.fileName()));
|
||||||
if (!copyResult)
|
if (!copyResult)
|
||||||
qWarning() << QString("Could not copy '%1' to '%2' due to %3")
|
qWarning() << QString("Could not copy '%1' to '%2' due to %3")
|
||||||
|
@@ -739,7 +739,7 @@ public:
|
|||||||
Utils::expected_str<QString> renameWorkspace(const QString &originalFileName,
|
Utils::expected_str<QString> renameWorkspace(const QString &originalFileName,
|
||||||
const QString &newName);
|
const QString &newName);
|
||||||
|
|
||||||
Utils::expected_str<void> resetWorkspacePreset(const QString &fileName);
|
Utils::Result resetWorkspacePreset(const QString &fileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Save the currently active workspace.
|
* \brief Save the currently active workspace.
|
||||||
|
@@ -33,61 +33,60 @@ expected_str<QString> run(const CommandLine &cmdLine, const QByteArray &inputDat
|
|||||||
return p.readAllStandardOutput().trimmed();
|
return p.readAllStandardOutput().trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::expected_str<void> FileAccess::init(const Utils::FilePath &pathToBridge)
|
Result FileAccess::init(const FilePath &pathToBridge)
|
||||||
{
|
{
|
||||||
m_client = std::make_unique<Client>(pathToBridge);
|
m_client = std::make_unique<Client>(pathToBridge);
|
||||||
|
|
||||||
auto startResult = m_client->start();
|
auto startResult = m_client->start();
|
||||||
if (!startResult)
|
if (!startResult)
|
||||||
return make_unexpected(QString("Could not start cmdbridge: %1").arg(startResult.error()));
|
return Result::Error(QString("Could not start cmdbridge: %1").arg(startResult.error()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!startResult->isValid())
|
if (!startResult->isValid())
|
||||||
startResult->waitForFinished();
|
startResult->waitForFinished();
|
||||||
m_environment = startResult->takeResult();
|
m_environment = startResult->takeResult();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error starting cmdbridge: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error starting cmdbridge: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
}
|
}
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FileAccess::deployAndInit(
|
Result FileAccess::deployAndInit(const FilePath &libExecPath, const FilePath &remoteRootPath)
|
||||||
const FilePath &libExecPath, const FilePath &remoteRootPath)
|
|
||||||
{
|
{
|
||||||
if (remoteRootPath.isEmpty())
|
if (remoteRootPath.isEmpty())
|
||||||
return make_unexpected(Tr::tr("Remote root path is empty"));
|
return Result::Error(Tr::tr("Remote root path is empty"));
|
||||||
|
|
||||||
if (!remoteRootPath.isAbsolutePath())
|
if (!remoteRootPath.isAbsolutePath())
|
||||||
return make_unexpected(Tr::tr("Remote root path is not absolute"));
|
return Result::Error(Tr::tr("Remote root path is not absolute"));
|
||||||
|
|
||||||
const auto whichDD = run({remoteRootPath.withNewPath("which"), {"dd"}});
|
const auto whichDD = run({remoteRootPath.withNewPath("which"), {"dd"}});
|
||||||
|
|
||||||
if (!whichDD) // TODO: Support Windows?
|
if (!whichDD) // TODO: Support Windows?
|
||||||
return make_unexpected(Tr::tr("Could not find dd on remote host: %1").arg(whichDD.error()));
|
return Result::Error(Tr::tr("Could not find dd on remote host: %1").arg(whichDD.error()));
|
||||||
|
|
||||||
qCDebug(faLog) << "Found dd on remote host:" << *whichDD;
|
qCDebug(faLog) << "Found dd on remote host:" << *whichDD;
|
||||||
|
|
||||||
const expected_str<QString> unameOs = run({remoteRootPath.withNewPath("uname"), {"-s"}});
|
const expected_str<QString> unameOs = run({remoteRootPath.withNewPath("uname"), {"-s"}});
|
||||||
if (!unameOs) {
|
if (!unameOs) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not determine OS on remote host: %1").arg(unameOs.error()));
|
QString("Could not determine OS on remote host: %1").arg(unameOs.error()));
|
||||||
}
|
}
|
||||||
Utils::expected_str<OsType> osType = osTypeFromString(*unameOs);
|
Utils::expected_str<OsType> osType = osTypeFromString(*unameOs);
|
||||||
if (!osType)
|
if (!osType)
|
||||||
return make_unexpected(osType.error());
|
return Result::Error(osType.error());
|
||||||
|
|
||||||
qCDebug(faLog) << "Remote host OS:" << *unameOs;
|
qCDebug(faLog) << "Remote host OS:" << *unameOs;
|
||||||
|
|
||||||
const expected_str<QString> unameArch = run({remoteRootPath.withNewPath("uname"), {"-m"}});
|
const expected_str<QString> unameArch = run({remoteRootPath.withNewPath("uname"), {"-m"}});
|
||||||
if (!unameArch) {
|
if (!unameArch) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not determine architecture on remote host: %1").arg(unameArch.error()));
|
QString("Could not determine architecture on remote host: %1").arg(unameArch.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::expected_str<OsArch> osArch = osArchFromString(*unameArch);
|
const Utils::expected_str<OsArch> osArch = osArchFromString(*unameArch);
|
||||||
if (!osArch)
|
if (!osArch)
|
||||||
return make_unexpected(osArch.error());
|
return Result::Error(osArch.error());
|
||||||
|
|
||||||
qCDebug(faLog) << "Remote host architecture:" << *unameArch;
|
qCDebug(faLog) << "Remote host architecture:" << *unameArch;
|
||||||
|
|
||||||
@@ -95,7 +94,7 @@ expected_str<void> FileAccess::deployAndInit(
|
|||||||
= Client::getCmdBridgePath(*osType, *osArch, libExecPath);
|
= Client::getCmdBridgePath(*osType, *osArch, libExecPath);
|
||||||
|
|
||||||
if (!cmdBridgePath) {
|
if (!cmdBridgePath) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not determine compatible cmdbridge for remote host: %1")
|
QString("Could not determine compatible cmdbridge for remote host: %1")
|
||||||
.arg(cmdBridgePath.error()));
|
.arg(cmdBridgePath.error()));
|
||||||
}
|
}
|
||||||
@@ -106,7 +105,7 @@ expected_str<void> FileAccess::deployAndInit(
|
|||||||
const auto cmdBridgeFileData = cmdBridgePath->fileContents();
|
const auto cmdBridgeFileData = cmdBridgePath->fileContents();
|
||||||
|
|
||||||
if (!cmdBridgeFileData) {
|
if (!cmdBridgeFileData) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not read cmdbridge file: %1").arg(cmdBridgeFileData.error()));
|
QString("Could not read cmdbridge file: %1").arg(cmdBridgeFileData.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ expected_str<void> FileAccess::deployAndInit(
|
|||||||
{remoteRootPath.withNewPath("mktemp"), {"-t", "cmdbridge.XXXXXXXXXX"}});
|
{remoteRootPath.withNewPath("mktemp"), {"-t", "cmdbridge.XXXXXXXXXX"}});
|
||||||
|
|
||||||
if (!tmpFile) {
|
if (!tmpFile) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not create temporary file: %1").arg(tmpFile.error()));
|
QString("Could not create temporary file: %1").arg(tmpFile.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +124,7 @@ expected_str<void> FileAccess::deployAndInit(
|
|||||||
const auto makeExecutable = run({remoteRootPath.withNewPath("chmod"), {"+x", *tmpFile}});
|
const auto makeExecutable = run({remoteRootPath.withNewPath("chmod"), {"+x", *tmpFile}});
|
||||||
|
|
||||||
if (!makeExecutable) {
|
if (!makeExecutable) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
QString("Could not make temporary file executable: %1").arg(makeExecutable.error()));
|
QString("Could not make temporary file executable: %1").arg(makeExecutable.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,26 +467,26 @@ expected_str<qint64> FileAccess::writeFileContents(const FilePath &filePath,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FileAccess::removeFile(const Utils::FilePath &filePath) const
|
Result FileAccess::removeFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Utils::expected_str<QFuture<void>> f = m_client->removeFile(filePath.nativePath());
|
Utils::expected_str<QFuture<void>> f = m_client->removeFile(filePath.nativePath());
|
||||||
if (!f)
|
if (!f)
|
||||||
return make_unexpected(f.error());
|
return Result::Error(f.error());
|
||||||
f->waitForFinished();
|
f->waitForFinished();
|
||||||
} catch (const std::system_error &e) {
|
} catch (const std::system_error &e) {
|
||||||
if (e.code().value() == ENOENT)
|
if (e.code().value() == ENOENT)
|
||||||
return make_unexpected(Tr::tr("File does not exist"));
|
return Result::Error(Tr::tr("File does not exist"));
|
||||||
qCWarning(faLog) << "Error removing file:" << e.what();
|
qCWarning(faLog) << "Error removing file:" << e.what();
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
qCWarning(faLog) << "Error removing file:" << e.what();
|
qCWarning(faLog) << "Error removing file:" << e.what();
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error removing file: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileAccess::removeRecursively(const Utils::FilePath &filePath, QString *error) const
|
bool FileAccess::removeRecursively(const Utils::FilePath &filePath, QString *error) const
|
||||||
@@ -530,37 +529,35 @@ bool FileAccess::createDirectory(const Utils::FilePath &filePath) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FileAccess::copyFile(const Utils::FilePath &filePath,
|
Result FileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
|
||||||
const Utils::FilePath &target) const
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto f = m_client->copyFile(filePath.nativePath(), target.nativePath());
|
auto f = m_client->copyFile(filePath.nativePath(), target.nativePath());
|
||||||
QTC_ASSERT_EXPECTED(f, return {});
|
QTC_ASSERT_EXPECTED(f, return Result::Ok);
|
||||||
f->waitForFinished();
|
f->waitForFinished();
|
||||||
return {};
|
return Result::Ok;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error copying file: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error copying file: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FileAccess::renameFile(
|
Result FileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
|
||||||
const Utils::FilePath &filePath, const Utils::FilePath &target) const
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Utils::expected_str<QFuture<void>> f
|
Utils::expected_str<QFuture<void>> f
|
||||||
= m_client->renameFile(filePath.nativePath(), target.nativePath());
|
= m_client->renameFile(filePath.nativePath(), target.nativePath());
|
||||||
if (!f)
|
if (!f)
|
||||||
return make_unexpected(f.error());
|
return Result::Error(f.error());
|
||||||
f->waitForFinished();
|
f->waitForFinished();
|
||||||
if (!f)
|
if (!f)
|
||||||
return make_unexpected(f.error());
|
return Result::Error(f.error());
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error renaming file: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error renaming file: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment FileAccess::deviceEnvironment() const
|
Environment FileAccess::deviceEnvironment() const
|
||||||
@@ -574,15 +571,15 @@ expected_str<std::unique_ptr<FilePathWatcher>> FileAccess::watch(const FilePath
|
|||||||
return m_client->watch(filePath.nativePath());
|
return m_client->watch(filePath.nativePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::expected_str<void> FileAccess::signalProcess(int pid, ControlSignal signal) const
|
Result FileAccess::signalProcess(int pid, ControlSignal signal) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto f = m_client->signalProcess(pid, signal);
|
auto f = m_client->signalProcess(pid, signal);
|
||||||
QTC_ASSERT_EXPECTED(f, return {});
|
QTC_ASSERT_EXPECTED(f, return Result::Ok);
|
||||||
f->waitForFinished();
|
f->waitForFinished();
|
||||||
return {};
|
return Result::Ok;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error killing process: %1").arg(QString::fromLocal8Bit(e.what())));
|
Tr::tr("Error killing process: %1").arg(QString::fromLocal8Bit(e.what())));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -27,17 +27,17 @@ class QTCREATOR_CMDBRIDGE_EXPORT FileAccess : public Utils::DeviceFileAccess
|
|||||||
public:
|
public:
|
||||||
~FileAccess() override;
|
~FileAccess() override;
|
||||||
|
|
||||||
Utils::expected_str<void> deployAndInit(
|
Utils::Result deployAndInit(
|
||||||
const Utils::FilePath &libExecPath, const Utils::FilePath &remoteRootPath);
|
const Utils::FilePath &libExecPath, const Utils::FilePath &remoteRootPath);
|
||||||
|
|
||||||
Utils::expected_str<void> init(const Utils::FilePath &pathToBridge);
|
Utils::Result init(const Utils::FilePath &pathToBridge);
|
||||||
|
|
||||||
Utils::expected_str<void> signalProcess(int pid, Utils::ControlSignal signal) const;
|
Utils::Result signalProcess(int pid, Utils::ControlSignal signal) const;
|
||||||
|
|
||||||
Utils::Environment deviceEnvironment() const override;
|
Utils::Environment deviceEnvironment() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Utils::expected_str<void> reinit();
|
Utils::Result reinit();
|
||||||
|
|
||||||
void iterateDirectory(const Utils::FilePath &filePath,
|
void iterateDirectory(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath::IterateDirCallback &callBack,
|
const Utils::FilePath::IterateDirCallback &callBack,
|
||||||
@@ -69,16 +69,16 @@ protected:
|
|||||||
Utils::expected_str<qint64> writeFileContents(const Utils::FilePath &filePath,
|
Utils::expected_str<qint64> writeFileContents(const Utils::FilePath &filePath,
|
||||||
const QByteArray &data) const override;
|
const QByteArray &data) const override;
|
||||||
|
|
||||||
Utils::expected_str<void> removeFile(const Utils::FilePath &filePath) const override;
|
Utils::Result removeFile(const Utils::FilePath &filePath) const override;
|
||||||
bool removeRecursively(const Utils::FilePath &filePath, QString *error) const override;
|
bool removeRecursively(const Utils::FilePath &filePath, QString *error) const override;
|
||||||
|
|
||||||
bool ensureExistingFile(const Utils::FilePath &filePath) const override;
|
bool ensureExistingFile(const Utils::FilePath &filePath) const override;
|
||||||
bool createDirectory(const Utils::FilePath &filePath) const override;
|
bool createDirectory(const Utils::FilePath &filePath) const override;
|
||||||
|
|
||||||
Utils::expected_str<void> copyFile(const Utils::FilePath &filePath,
|
Utils::Result copyFile(const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &target) const override;
|
const Utils::FilePath &target) const override;
|
||||||
|
|
||||||
Utils::expected_str<void> renameFile(
|
Utils::Result renameFile(
|
||||||
const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||||
|
|
||||||
Utils::expected_str<Utils::FilePath> createTempFile(const Utils::FilePath &filePath) override;
|
Utils::expected_str<Utils::FilePath> createTempFile(const Utils::FilePath &filePath) override;
|
||||||
|
@@ -117,22 +117,21 @@ bool DeviceFileAccess::hasHardLinks(const FilePath &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
|
Result DeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (isWritableDirectory(filePath))
|
if (isWritableDirectory(filePath))
|
||||||
return {};
|
return Result::Ok;
|
||||||
|
|
||||||
if (exists(filePath)) {
|
if (exists(filePath)) {
|
||||||
return make_unexpected(Tr::tr("Path \"%1\" exists but is not a writable directory.")
|
return Result::Error(Tr::tr("Path \"%1\" exists but is not a writable directory.")
|
||||||
.arg(filePath.toUserOutput()));
|
.arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool result = createDirectory(filePath);
|
const bool result = createDirectory(filePath);
|
||||||
if (result)
|
if (result)
|
||||||
return {};
|
return Result::Ok;
|
||||||
|
|
||||||
return make_unexpected(
|
return Result::Error(Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
|
||||||
Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
|
bool DeviceFileAccess::ensureExistingFile(const FilePath &filePath) const
|
||||||
@@ -155,11 +154,10 @@ bool DeviceFileAccess::exists(const FilePath &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DeviceFileAccess::removeFile(const FilePath &filePath) const
|
Result DeviceFileAccess::removeFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("removeFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
Tr::tr("removeFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,18 +169,17 @@ bool DeviceFileAccess::removeRecursively(const FilePath &filePath, QString *erro
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
|
Result DeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
|
||||||
Q_UNUSED(target)
|
Q_UNUSED(target)
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("copyFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
Tr::tr("copyFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> copyRecursively_fallback(const FilePath &src, const FilePath &target)
|
static Result copyRecursively_fallback(const FilePath &src, const FilePath &target)
|
||||||
{
|
{
|
||||||
expected_str<void> result;
|
Result result = Result::Ok;
|
||||||
src.iterateDirectory(
|
src.iterateDirectory(
|
||||||
[&target, &src, &result](const FilePath &path) {
|
[&target, &src, &result](const FilePath &path) {
|
||||||
const FilePath relative = path.relativePathFrom(src);
|
const FilePath relative = path.relativePathFrom(src);
|
||||||
@@ -202,16 +199,15 @@ expected_str<void> copyRecursively_fallback(const FilePath &src, const FilePath
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DeviceFileAccess::copyRecursively(const FilePath &src,
|
Result DeviceFileAccess::copyRecursively(const FilePath &src, const FilePath &target) const
|
||||||
const FilePath &target) const
|
|
||||||
{
|
{
|
||||||
if (!src.isDir()) {
|
if (!src.isDir()) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Cannot copy from \"%1\", it is not a directory.").arg(src.toUserOutput()));
|
Tr::tr("Cannot copy from \"%1\", it is not a directory.").arg(src.toUserOutput()));
|
||||||
}
|
}
|
||||||
const expected_str<void> result = target.ensureWritableDir();
|
const Result result = target.ensureWritableDir();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return make_unexpected(Tr::tr("Cannot copy \"%1\" to \"%2\": %3")
|
return Result::Error(Tr::tr("Cannot copy \"%1\" to \"%2\": %3")
|
||||||
.arg(src.toUserOutput())
|
.arg(src.toUserOutput())
|
||||||
.arg(target.toUserOutput())
|
.arg(target.toUserOutput())
|
||||||
.arg(result.error()));
|
.arg(result.error()));
|
||||||
@@ -254,7 +250,7 @@ expected_str<void> DeviceFileAccess::copyRecursively(const FilePath &src,
|
|||||||
|
|
||||||
if (srcProcess.result() != ProcessResult::FinishedWithSuccess) {
|
if (srcProcess.result() != ProcessResult::FinishedWithSuccess) {
|
||||||
targetProcess.kill();
|
targetProcess.kill();
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
|
Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
|
||||||
"trying to create tar archive from source: %3")
|
"trying to create tar archive from source: %3")
|
||||||
.arg(src.toUserOutput(), target.toUserOutput(), srcProcess.readAllStandardError()));
|
.arg(src.toUserOutput(), target.toUserOutput(), srcProcess.readAllStandardError()));
|
||||||
@@ -263,23 +259,22 @@ expected_str<void> DeviceFileAccess::copyRecursively(const FilePath &src,
|
|||||||
targetProcess.waitForFinished();
|
targetProcess.waitForFinished();
|
||||||
|
|
||||||
if (targetProcess.result() != ProcessResult::FinishedWithSuccess) {
|
if (targetProcess.result() != ProcessResult::FinishedWithSuccess) {
|
||||||
return make_unexpected(Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
|
return Result::Error(Tr::tr("Failed to copy recursively from \"%1\" to \"%2\" while "
|
||||||
"trying to extract tar archive to target: %3")
|
"trying to extract tar archive to target: %3")
|
||||||
.arg(src.toUserOutput(),
|
.arg(src.toUserOutput(),
|
||||||
target.toUserOutput(),
|
target.toUserOutput(),
|
||||||
targetProcess.readAllStandardError()));
|
targetProcess.readAllStandardError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return Result::Ok;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
|
Result DeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(filePath)
|
|
||||||
Q_UNUSED(target)
|
Q_UNUSED(target)
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("renameFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
Tr::tr("renameFile is not implemented for \"%1\".").arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,22 +679,22 @@ bool DesktopDeviceFileAccess::hasHardLinks(const FilePath &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DesktopDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
|
Result DesktopDeviceFileAccess::ensureWritableDirectory(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
const QFileInfo fi(filePath.path());
|
const QFileInfo fi(filePath.path());
|
||||||
if (fi.isDir() && fi.isWritable())
|
if (fi.isDir() && fi.isWritable())
|
||||||
return {};
|
return Result::Ok;
|
||||||
|
|
||||||
if (fi.exists()) {
|
if (fi.exists()) {
|
||||||
return make_unexpected(Tr::tr("Path \"%1\" exists but is not a writable directory.")
|
return Result::Error(Tr::tr("Path \"%1\" exists but is not a writable directory.")
|
||||||
.arg(filePath.toUserOutput()));
|
.arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool result = QDir().mkpath(filePath.path());
|
const bool result = QDir().mkpath(filePath.path());
|
||||||
if (result)
|
if (result)
|
||||||
return {};
|
return Result::Ok;
|
||||||
|
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
|
Tr::tr("Failed to create directory \"%1\".").arg(filePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -724,12 +719,12 @@ bool DesktopDeviceFileAccess::exists(const FilePath &filePath) const
|
|||||||
return !filePath.isEmpty() && QFileInfo::exists(filePath.path());
|
return !filePath.isEmpty() && QFileInfo::exists(filePath.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DesktopDeviceFileAccess::removeFile(const FilePath &filePath) const
|
Result DesktopDeviceFileAccess::removeFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
QFile f(filePath.path());
|
QFile f(filePath.path());
|
||||||
if (!f.remove())
|
if (!f.remove())
|
||||||
return make_unexpected(f.errorString());
|
return Result::Error(f.errorString());
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkToRefuseRemoveStandardLocationDirectory(const QString &dirPath,
|
static bool checkToRefuseRemoveStandardLocationDirectory(const QString &dirPath,
|
||||||
@@ -806,26 +801,26 @@ bool DesktopDeviceFileAccess::removeRecursively(const FilePath &filePath, QStrin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DesktopDeviceFileAccess::copyFile(const FilePath &filePath,
|
Result DesktopDeviceFileAccess::copyFile(const FilePath &filePath,
|
||||||
const FilePath &target) const
|
const FilePath &target) const
|
||||||
{
|
{
|
||||||
QFile srcFile(filePath.path());
|
QFile srcFile(filePath.path());
|
||||||
|
|
||||||
if (srcFile.copy(target.path()))
|
if (srcFile.copy(target.path()))
|
||||||
return {};
|
return Result::Ok;
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
|
Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
|
||||||
.arg(filePath.toUserOutput(), target.toUserOutput(), srcFile.errorString()));
|
.arg(filePath.toUserOutput(), target.toUserOutput(), srcFile.errorString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> DesktopDeviceFileAccess::renameFile(
|
Result DesktopDeviceFileAccess::renameFile(
|
||||||
const FilePath &filePath, const FilePath &target) const
|
const FilePath &filePath, const FilePath &target) const
|
||||||
{
|
{
|
||||||
QFile f(filePath.path());
|
QFile f(filePath.path());
|
||||||
|
|
||||||
if (f.rename(target.path()))
|
if (f.rename(target.path()))
|
||||||
return {};
|
return Result::Ok;
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
|
Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
|
||||||
.arg(filePath.toUserOutput(), target.toUserOutput(), f.errorString()));
|
.arg(filePath.toUserOutput(), target.toUserOutput(), f.errorString()));
|
||||||
}
|
}
|
||||||
@@ -1060,9 +1055,14 @@ QByteArray DesktopDeviceFileAccess::fileId(const FilePath &filePath) const
|
|||||||
|
|
||||||
// UnixDeviceAccess
|
// UnixDeviceAccess
|
||||||
|
|
||||||
|
static QString disconnectedMessage()
|
||||||
|
{
|
||||||
|
return Tr::tr("Device is not connected");
|
||||||
|
}
|
||||||
|
|
||||||
static Utils::unexpected<QString> make_unexpected_disconnected()
|
static Utils::unexpected<QString> make_unexpected_disconnected()
|
||||||
{
|
{
|
||||||
return make_unexpected(Tr::tr("Device is not connected"));
|
return make_unexpected(disconnectedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
UnixDeviceFileAccess::~UnixDeviceFileAccess() = default;
|
UnixDeviceFileAccess::~UnixDeviceFileAccess() = default;
|
||||||
@@ -1175,20 +1175,21 @@ bool UnixDeviceFileAccess::exists(const FilePath &filePath) const
|
|||||||
return runInShellSuccess({"test", {"-e", path}, OsType::OsTypeLinux});
|
return runInShellSuccess({"test", {"-e", path}, OsType::OsTypeLinux});
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> UnixDeviceFileAccess::removeFile(const FilePath &filePath) const
|
Result UnixDeviceFileAccess::removeFile(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
if (disconnected())
|
if (disconnected())
|
||||||
return make_unexpected_disconnected();
|
return Result::Error(disconnectedMessage());
|
||||||
RunResult result = runInShell({"rm", {filePath.path()}, OsType::OsTypeLinux});
|
RunResult result = runInShell({"rm", {filePath.path()}, OsType::OsTypeLinux});
|
||||||
if (result.exitCode != 0)
|
if (result.exitCode != 0)
|
||||||
return make_unexpected(QString::fromUtf8(result.stdErr));
|
return Result::Error(QString::fromUtf8(result.stdErr));
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString *error) const
|
bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString *error) const
|
||||||
{
|
{
|
||||||
if (disconnected())
|
if (disconnected())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QTC_ASSERT(filePath.path().startsWith('/'), return false);
|
QTC_ASSERT(filePath.path().startsWith('/'), return false);
|
||||||
|
|
||||||
const QString path = filePath.cleanPath().path();
|
const QString path = filePath.cleanPath().path();
|
||||||
@@ -1206,36 +1207,35 @@ bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString *
|
|||||||
return result.exitCode == 0;
|
return result.exitCode == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> UnixDeviceFileAccess::copyFile(const FilePath &filePath,
|
Result UnixDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const
|
||||||
const FilePath &target) const
|
|
||||||
{
|
{
|
||||||
if (disconnected())
|
if (disconnected())
|
||||||
return make_unexpected_disconnected();
|
return Result::Error(disconnectedMessage());
|
||||||
const RunResult result = runInShell(
|
const RunResult result = runInShell(
|
||||||
{"cp", {filePath.path(), target.path()}, OsType::OsTypeLinux});
|
{"cp", {filePath.path(), target.path()}, OsType::OsTypeLinux});
|
||||||
|
|
||||||
if (result.exitCode != 0) {
|
if (result.exitCode != 0) {
|
||||||
return make_unexpected(Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
|
return Result::Error(Tr::tr("Failed to copy file \"%1\" to \"%2\": %3")
|
||||||
.arg(filePath.toUserOutput(),
|
.arg(filePath.toUserOutput(),
|
||||||
target.toUserOutput(),
|
target.toUserOutput(),
|
||||||
QString::fromUtf8(result.stdErr)));
|
QString::fromUtf8(result.stdErr)));
|
||||||
}
|
}
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> UnixDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
|
Result UnixDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const
|
||||||
{
|
{
|
||||||
if (disconnected())
|
if (disconnected())
|
||||||
return make_unexpected_disconnected();
|
return Result::Error(disconnectedMessage());
|
||||||
|
|
||||||
auto result = runInShell({"mv", {filePath.path(), target.path()}, OsType::OsTypeLinux});
|
RunResult result = runInShell({"mv", {filePath.path(), target.path()}, OsType::OsTypeLinux});
|
||||||
if (result.exitCode != 0) {
|
if (result.exitCode != 0) {
|
||||||
return make_unexpected(Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
|
return Result::Error(Tr::tr("Failed to rename file \"%1\" to \"%2\": %3")
|
||||||
.arg(filePath.toUserOutput(),
|
.arg(filePath.toUserOutput(),
|
||||||
target.toUserOutput(),
|
target.toUserOutput(),
|
||||||
QString::fromUtf8(result.stdErr)));
|
QString::fromUtf8(result.stdErr)));
|
||||||
}
|
}
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath UnixDeviceFileAccess::symLinkTarget(const FilePath &filePath) const
|
FilePath UnixDeviceFileAccess::symLinkTarget(const FilePath &filePath) const
|
||||||
|
@@ -38,16 +38,15 @@ protected:
|
|||||||
virtual bool isDirectory(const FilePath &filePath) const;
|
virtual bool isDirectory(const FilePath &filePath) const;
|
||||||
virtual bool isSymLink(const FilePath &filePath) const;
|
virtual bool isSymLink(const FilePath &filePath) const;
|
||||||
virtual bool hasHardLinks(const FilePath &filePath) const;
|
virtual bool hasHardLinks(const FilePath &filePath) const;
|
||||||
virtual expected_str<void> ensureWritableDirectory(const FilePath &filePath) const;
|
virtual Result ensureWritableDirectory(const FilePath &filePath) const;
|
||||||
virtual bool ensureExistingFile(const FilePath &filePath) const;
|
virtual bool ensureExistingFile(const FilePath &filePath) const;
|
||||||
virtual bool createDirectory(const FilePath &filePath) const;
|
virtual bool createDirectory(const FilePath &filePath) const;
|
||||||
virtual bool exists(const FilePath &filePath) const;
|
virtual bool exists(const FilePath &filePath) const;
|
||||||
virtual expected_str<void> removeFile(const FilePath &filePath) const;
|
virtual Result removeFile(const FilePath &filePath) const;
|
||||||
virtual bool removeRecursively(const FilePath &filePath, QString *error) const;
|
virtual bool removeRecursively(const FilePath &filePath, QString *error) const;
|
||||||
virtual expected_str<void> copyFile(const FilePath &filePath, const FilePath &target) const;
|
virtual Result copyFile(const FilePath &filePath, const FilePath &target) const;
|
||||||
virtual expected_str<void> copyRecursively(const FilePath &filePath,
|
virtual Result copyRecursively(const FilePath &filePath, const FilePath &target) const;
|
||||||
const FilePath &target) const;
|
virtual Result renameFile(const FilePath &filePath, const FilePath &target) const;
|
||||||
virtual expected_str<void> renameFile(const FilePath &filePath, const FilePath &target) const;
|
|
||||||
|
|
||||||
virtual FilePath symLinkTarget(const FilePath &filePath) const;
|
virtual FilePath symLinkTarget(const FilePath &filePath) const;
|
||||||
virtual FilePathInfo filePathInfo(const FilePath &filePath) const;
|
virtual FilePathInfo filePathInfo(const FilePath &filePath) const;
|
||||||
@@ -97,14 +96,14 @@ protected:
|
|||||||
bool isDirectory(const FilePath &filePath) const override;
|
bool isDirectory(const FilePath &filePath) const override;
|
||||||
bool isSymLink(const FilePath &filePath) const override;
|
bool isSymLink(const FilePath &filePath) const override;
|
||||||
bool hasHardLinks(const FilePath &filePath) const override;
|
bool hasHardLinks(const FilePath &filePath) const override;
|
||||||
expected_str<void> ensureWritableDirectory(const FilePath &filePath) const override;
|
Result ensureWritableDirectory(const FilePath &filePath) const override;
|
||||||
bool ensureExistingFile(const FilePath &filePath) const override;
|
bool ensureExistingFile(const FilePath &filePath) const override;
|
||||||
bool createDirectory(const FilePath &filePath) const override;
|
bool createDirectory(const FilePath &filePath) const override;
|
||||||
bool exists(const FilePath &filePath) const override;
|
bool exists(const FilePath &filePath) const override;
|
||||||
expected_str<void> removeFile(const FilePath &filePath) const override;
|
Result removeFile(const FilePath &filePath) const override;
|
||||||
bool removeRecursively(const FilePath &filePath, QString *error) const override;
|
bool removeRecursively(const FilePath &filePath, QString *error) const override;
|
||||||
expected_str<void> copyFile(const FilePath &filePath, const FilePath &target) const override;
|
Result copyFile(const FilePath &filePath, const FilePath &target) const override;
|
||||||
expected_str<void> renameFile(const FilePath &filePath, const FilePath &target) const override;
|
Result renameFile(const FilePath &filePath, const FilePath &target) const override;
|
||||||
|
|
||||||
FilePath symLinkTarget(const FilePath &filePath) const override;
|
FilePath symLinkTarget(const FilePath &filePath) const override;
|
||||||
FilePathInfo filePathInfo(const FilePath &filePath) const override;
|
FilePathInfo filePathInfo(const FilePath &filePath) const override;
|
||||||
@@ -159,10 +158,10 @@ protected:
|
|||||||
bool ensureExistingFile(const FilePath &filePath) const override;
|
bool ensureExistingFile(const FilePath &filePath) const override;
|
||||||
bool createDirectory(const FilePath &filePath) const override;
|
bool createDirectory(const FilePath &filePath) const override;
|
||||||
bool exists(const FilePath &filePath) const override;
|
bool exists(const FilePath &filePath) const override;
|
||||||
expected_str<void> removeFile(const FilePath &filePath) const override;
|
Result removeFile(const FilePath &filePath) const override;
|
||||||
bool removeRecursively(const FilePath &filePath, QString *error) const override;
|
bool removeRecursively(const FilePath &filePath, QString *error) const override;
|
||||||
expected_str<void> copyFile(const FilePath &filePath, const FilePath &target) const override;
|
Result copyFile(const FilePath &filePath, const FilePath &target) const override;
|
||||||
expected_str<void> renameFile(const FilePath &filePath, const FilePath &target) const override;
|
Result renameFile(const FilePath &filePath, const FilePath &target) const override;
|
||||||
|
|
||||||
FilePathInfo filePathInfo(const FilePath &filePath) const override;
|
FilePathInfo filePathInfo(const FilePath &filePath) const override;
|
||||||
FilePath symLinkTarget(const FilePath &filePath) const override;
|
FilePath symLinkTarget(const FilePath &filePath) const override;
|
||||||
|
@@ -551,7 +551,7 @@ void FilePath::setParts(const QStringView scheme, const QStringView host, QStrin
|
|||||||
|
|
||||||
\sa createDir()
|
\sa createDir()
|
||||||
*/
|
*/
|
||||||
expected_str<void> FilePath::ensureWritableDir() const
|
Result FilePath::ensureWritableDir() const
|
||||||
{
|
{
|
||||||
return fileAccess()->ensureWritableDirectory(*this);
|
return fileAccess()->ensureWritableDirectory(*this);
|
||||||
}
|
}
|
||||||
@@ -1980,7 +1980,7 @@ OsType FilePath::osType() const
|
|||||||
return s_deviceHooks.osType(*this);
|
return s_deviceHooks.osType(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FilePath::removeFile() const
|
Result FilePath::removeFile() const
|
||||||
{
|
{
|
||||||
return fileAccess()->removeFile(*this);
|
return fileAccess()->removeFile(*this);
|
||||||
}
|
}
|
||||||
@@ -1997,18 +1997,18 @@ bool FilePath::removeRecursively(QString *error) const
|
|||||||
return fileAccess()->removeRecursively(*this, error);
|
return fileAccess()->removeRecursively(*this, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FilePath::copyRecursively(const FilePath &target) const
|
Result FilePath::copyRecursively(const FilePath &target) const
|
||||||
{
|
{
|
||||||
return fileAccess()->copyRecursively(*this, target);
|
return fileAccess()->copyRecursively(*this, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FilePath::copyFile(const FilePath &target) const
|
Result FilePath::copyFile(const FilePath &target) const
|
||||||
{
|
{
|
||||||
if (!isSameDevice(target)) {
|
if (!isSameDevice(target)) {
|
||||||
// FIXME: This does not scale.
|
// FIXME: This does not scale.
|
||||||
const expected_str<QByteArray> contents = fileContents();
|
const expected_str<QByteArray> contents = fileContents();
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Error while trying to copy file: %1").arg(contents.error()));
|
Tr::tr("Error while trying to copy file: %1").arg(contents.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2016,38 +2016,41 @@ expected_str<void> FilePath::copyFile(const FilePath &target) const
|
|||||||
const expected_str<qint64> copyResult = target.writeFileContents(*contents);
|
const expected_str<qint64> copyResult = target.writeFileContents(*contents);
|
||||||
|
|
||||||
if (!copyResult)
|
if (!copyResult)
|
||||||
return make_unexpected(Tr::tr("Could not copy file: %1").arg(copyResult.error()));
|
return Result::Error(Tr::tr("Could not copy file: %1").arg(copyResult.error()));
|
||||||
|
|
||||||
if (!target.setPermissions(perms)) {
|
if (!target.setPermissions(perms)) {
|
||||||
target.removeFile();
|
target.removeFile();
|
||||||
return make_unexpected(
|
return Result::Error(
|
||||||
Tr::tr("Could not set permissions on \"%1\"").arg(target.toString()));
|
Tr::tr("Could not set permissions on \"%1\"").arg(target.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return Result::Ok;
|
||||||
}
|
}
|
||||||
return fileAccess()->copyFile(*this, target);
|
return fileAccess()->copyFile(*this, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> FilePath::renameFile(const FilePath &target) const
|
Result FilePath::renameFile(const FilePath &target) const
|
||||||
{
|
{
|
||||||
if (isSameDevice(target))
|
if (isSameDevice(target))
|
||||||
return fileAccess()->renameFile(*this, target);
|
return fileAccess()->renameFile(*this, target);
|
||||||
|
|
||||||
return copyFile(target).and_then([this, &target] {
|
const Result copyResult = copyFile(target);
|
||||||
return removeFile().or_else(
|
if (!copyResult)
|
||||||
[this, &target](const QString &removeError) -> expected_str<void> {
|
return copyResult;
|
||||||
// If we fail to remove the source file, we remove the target file to return to the
|
|
||||||
// original state.
|
const Result removeResult = removeFile();
|
||||||
expected_str<void> rmResult = target.removeFile();
|
if (removeResult)
|
||||||
QTC_CHECK_EXPECTED(rmResult);
|
return Result::Ok;
|
||||||
return make_unexpected(
|
|
||||||
Tr::tr("Failed to move %1 to %2. Removing the source file failed: %3")
|
// If we fail to remove the source file, we remove the target file to return to the
|
||||||
.arg(toUserOutput())
|
// original state.
|
||||||
.arg(target.toUserOutput())
|
Result rmResult = target.removeFile();
|
||||||
.arg(removeError));
|
QTC_CHECK_EXPECTED(rmResult);
|
||||||
});
|
return Result::Error(
|
||||||
});
|
Tr::tr("Failed to move %1 to %2. Removing the source file failed: %3")
|
||||||
|
.arg(toUserOutput())
|
||||||
|
.arg(target.toUserOutput())
|
||||||
|
.arg(rmResult.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 FilePath::fileSize() const
|
qint64 FilePath::fileSize() const
|
||||||
|
@@ -152,7 +152,7 @@ public:
|
|||||||
|
|
||||||
bool isWritableDir() const;
|
bool isWritableDir() const;
|
||||||
bool isWritableFile() const;
|
bool isWritableFile() const;
|
||||||
expected_str<void> ensureWritableDir() const;
|
Result ensureWritableDir() const;
|
||||||
bool ensureExistingFile() const;
|
bool ensureExistingFile() const;
|
||||||
bool isExecutableFile() const;
|
bool isExecutableFile() const;
|
||||||
bool isReadableFile() const;
|
bool isReadableFile() const;
|
||||||
@@ -170,11 +170,11 @@ public:
|
|||||||
QFile::Permissions permissions() const;
|
QFile::Permissions permissions() const;
|
||||||
bool setPermissions(QFile::Permissions permissions) const;
|
bool setPermissions(QFile::Permissions permissions) const;
|
||||||
OsType osType() const;
|
OsType osType() const;
|
||||||
expected_str<void> removeFile() const;
|
Result removeFile() const;
|
||||||
bool removeRecursively(QString *error = nullptr) const;
|
bool removeRecursively(QString *error = nullptr) const;
|
||||||
expected_str<void> copyRecursively(const FilePath &target) const;
|
Result copyRecursively(const FilePath &target) const;
|
||||||
expected_str<void> copyFile(const FilePath &target) const;
|
Result copyFile(const FilePath &target) const;
|
||||||
expected_str<void> renameFile(const FilePath &target) const;
|
Result renameFile(const FilePath &target) const;
|
||||||
qint64 fileSize() const;
|
qint64 fileSize() const;
|
||||||
qint64 bytesAvailable() const;
|
qint64 bytesAvailable() const;
|
||||||
bool createDir() const;
|
bool createDir() const;
|
||||||
|
@@ -735,7 +735,7 @@ bool FileUtils::copyIfDifferent(const FilePath &srcFilePath, const FilePath &tgt
|
|||||||
tgtFilePath.removeFile();
|
tgtFilePath.removeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
const expected_str<void> copyResult = srcFilePath.copyFile(tgtFilePath);
|
const Result copyResult = srcFilePath.copyFile(tgtFilePath);
|
||||||
|
|
||||||
// TODO forward error to caller instead of assert, since IO errors can always be expected
|
// TODO forward error to caller instead of assert, since IO errors can always be expected
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return false);
|
QTC_ASSERT_EXPECTED(copyResult, return false);
|
||||||
|
@@ -220,18 +220,18 @@ bool FSEngineImpl::remove()
|
|||||||
|
|
||||||
bool FSEngineImpl::copy(const QString &newName)
|
bool FSEngineImpl::copy(const QString &newName)
|
||||||
{
|
{
|
||||||
expected_str<void> result = m_filePath.copyFile(FilePath::fromString(newName));
|
Result result = m_filePath.copyFile(FilePath::fromString(newName));
|
||||||
if (!result)
|
if (!result)
|
||||||
setError(QFile::CopyError, result.error());
|
setError(QFile::CopyError, result.error());
|
||||||
return result.has_value();
|
return bool(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FSEngineImpl::rename(const QString &newName)
|
bool FSEngineImpl::rename(const QString &newName)
|
||||||
{
|
{
|
||||||
auto result = m_filePath.renameFile(FilePath::fromString(newName));
|
Result result = m_filePath.renameFile(FilePath::fromString(newName));
|
||||||
if (!result)
|
if (!result)
|
||||||
setError(QFile::RenameError, result.error());
|
setError(QFile::RenameError, result.error());
|
||||||
return result.has_value();
|
return bool(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FSEngineImpl::renameOverwrite(const QString &newName)
|
bool FSEngineImpl::renameOverwrite(const QString &newName)
|
||||||
|
@@ -197,7 +197,7 @@ bool SaveFile::commit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> renameResult = m_tempFile->filePath().renameFile(finalFileName);
|
Result renameResult = m_tempFile->filePath().renameFile(finalFileName);
|
||||||
if (!renameResult) {
|
if (!renameResult) {
|
||||||
// The case when someone else was able to create finalFileName after we've renamed it.
|
// The case when someone else was able to create finalFileName after we've renamed it.
|
||||||
// Higher level call may try to save this file again but here we do nothing and
|
// Higher level call may try to save this file again but here we do nothing and
|
||||||
|
@@ -679,7 +679,7 @@ static bool copyFileIfNewer(const FilePath &sourceFilePath,
|
|||||||
|
|
||||||
if (!destinationFilePath.parentDir().ensureWritableDir())
|
if (!destinationFilePath.parentDir().ensureWritableDir())
|
||||||
return false;
|
return false;
|
||||||
expected_str<void> result = sourceFilePath.copyFile(destinationFilePath);
|
Result result = sourceFilePath.copyFile(destinationFilePath);
|
||||||
QTC_ASSERT_EXPECTED(result, return false);
|
QTC_ASSERT_EXPECTED(result, return false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -187,7 +187,7 @@ bool FileUtils::renameFile(const FilePath &orgFilePath, const FilePath &newFileP
|
|||||||
if (vc && vc->supportsOperation(IVersionControl::MoveOperation))
|
if (vc && vc->supportsOperation(IVersionControl::MoveOperation))
|
||||||
result = vc->vcsMove(orgFilePath, newFilePath);
|
result = vc->vcsMove(orgFilePath, newFilePath);
|
||||||
if (!result) // The moving via vcs failed or the vcs does not support moving, fall back
|
if (!result) // The moving via vcs failed or the vcs does not support moving, fall back
|
||||||
result = orgFilePath.renameFile(newFilePath).has_value();
|
result = bool(orgFilePath.renameFile(newFilePath));
|
||||||
if (result) {
|
if (result) {
|
||||||
DocumentManager::renamedFile(orgFilePath, newFilePath);
|
DocumentManager::renamedFile(orgFilePath, newFilePath);
|
||||||
updateHeaderFileGuardIfApplicable(orgFilePath, newFilePath, handleGuards);
|
updateHeaderFileGuardIfApplicable(orgFilePath, newFilePath, handleGuards);
|
||||||
|
@@ -351,9 +351,9 @@ bool SessionManager::deleteSession(const QString &session)
|
|||||||
FilePath sessionFile = sessionNameToFileName(session);
|
FilePath sessionFile = sessionNameToFileName(session);
|
||||||
if (!sessionFile.exists())
|
if (!sessionFile.exists())
|
||||||
return false;
|
return false;
|
||||||
expected_str<void> result = sessionFile.removeFile();
|
Result result = sessionFile.removeFile();
|
||||||
QTC_CHECK_EXPECTED(result);
|
QTC_CHECK_EXPECTED(result);
|
||||||
return result.has_value();
|
return bool(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::deleteSessions(const QStringList &sessions)
|
void SessionManager::deleteSessions(const QStringList &sessions)
|
||||||
|
@@ -232,7 +232,7 @@ void AttachCoreDialog::accepted()
|
|||||||
const expected_str<FilePath> resultPath = pattern.createTempFile();
|
const expected_str<FilePath> resultPath = pattern.createTempFile();
|
||||||
if (!resultPath)
|
if (!resultPath)
|
||||||
return make_unexpected(resultPath.error());
|
return make_unexpected(resultPath.error());
|
||||||
const expected_str<void> result = srcPath.copyFile(resultPath.value());
|
const Result result = srcPath.copyFile(resultPath.value());
|
||||||
if (!result)
|
if (!result)
|
||||||
return make_unexpected(result.error());
|
return make_unexpected(result.error());
|
||||||
|
|
||||||
|
@@ -582,7 +582,7 @@ DockerDevice::DockerDevice()
|
|||||||
return make_unexpected(cmdBridgePath.error());
|
return make_unexpected(cmdBridgePath.error());
|
||||||
|
|
||||||
auto fAccess = std::make_unique<DockerDeviceFileAccess>(d);
|
auto fAccess = std::make_unique<DockerDeviceFileAccess>(d);
|
||||||
expected_str<void> initResult;
|
Result initResult = Result::Ok;
|
||||||
if (!cmdBridgePath->isSameDevice(Docker::Internal::settings().dockerBinaryPath())) {
|
if (!cmdBridgePath->isSameDevice(Docker::Internal::settings().dockerBinaryPath())) {
|
||||||
initResult = fAccess->deployAndInit(Core::ICore::libexecPath(), rootPath());
|
initResult = fAccess->deployAndInit(Core::ICore::libexecPath(), rootPath());
|
||||||
} else {
|
} else {
|
||||||
|
@@ -381,7 +381,7 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return oldPath.renameFile(newPath).has_value();
|
return bool(oldPath.renameFile(newPath));
|
||||||
} else if (const auto deleteOperation = std::get_if<DeleteFileOperation>(&change)) {
|
} else if (const auto deleteOperation = std::get_if<DeleteFileOperation>(&change)) {
|
||||||
const FilePath filePath = deleteOperation->uri().toFilePath(client->hostPathMapper());
|
const FilePath filePath = deleteOperation->uri().toFilePath(client->hostPathMapper());
|
||||||
if (const std::optional<DeleteFileOptions> options = deleteOperation->options()) {
|
if (const std::optional<DeleteFileOptions> options = deleteOperation->options()) {
|
||||||
@@ -390,7 +390,7 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
if (filePath.isDir() && options->recursive().value_or(false))
|
if (filePath.isDir() && options->recursive().value_or(false))
|
||||||
return filePath.removeRecursively();
|
return filePath.removeRecursively();
|
||||||
}
|
}
|
||||||
return filePath.removeFile().has_value();
|
return bool(filePath.removeFile());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -295,7 +295,7 @@ MacroExpander *BuildConfiguration::macroExpander() const
|
|||||||
|
|
||||||
bool BuildConfiguration::createBuildDirectory()
|
bool BuildConfiguration::createBuildDirectory()
|
||||||
{
|
{
|
||||||
const bool result = buildDirectory().ensureWritableDir().has_value();
|
const bool result = bool(buildDirectory().ensureWritableDir());
|
||||||
buildDirectoryAspect()->validateInput();
|
buildDirectoryAspect()->validateInput();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -158,8 +158,8 @@ QString AssetsLibraryModel::addNewFolder(const QString &folderPath)
|
|||||||
{
|
{
|
||||||
Utils::FilePath uniqueDirPath = Utils::FilePath::fromString(UniqueName::generatePath(folderPath));
|
Utils::FilePath uniqueDirPath = Utils::FilePath::fromString(UniqueName::generatePath(folderPath));
|
||||||
|
|
||||||
auto res = uniqueDirPath.ensureWritableDir();
|
const Utils::Result res = uniqueDirPath.ensureWritableDir();
|
||||||
if (!res.has_value()) {
|
if (!res) {
|
||||||
qWarning() << __FUNCTION__ << res.error();
|
qWarning() << __FUNCTION__ << res.error();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@@ -139,7 +139,7 @@ static FilePath copyToAlternativeLocation(const FilePath &proFile,
|
|||||||
QMessageBox::NoButton);
|
QMessageBox::NoButton);
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
expected_str<void> result = projectDir.copyRecursively(targetDir);
|
Result result = projectDir.copyRecursively(targetDir);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// set vars to new location
|
// set vars to new location
|
||||||
|
@@ -78,9 +78,7 @@ private:
|
|||||||
|
|
||||||
GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
|
GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
|
||||||
{
|
{
|
||||||
using ResultType = expected_str<void>;
|
const auto onSetup = [storage](Async<Result> &async) {
|
||||||
|
|
||||||
const auto onSetup = [storage](Async<ResultType> &async) {
|
|
||||||
FilePaths remoteDirs;
|
FilePaths remoteDirs;
|
||||||
for (const FileToTransfer &file : *storage)
|
for (const FileToTransfer &file : *storage)
|
||||||
remoteDirs << file.m_target.parentDir();
|
remoteDirs << file.m_target.parentDir();
|
||||||
@@ -88,9 +86,9 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
|
|||||||
FilePath::sort(remoteDirs);
|
FilePath::sort(remoteDirs);
|
||||||
FilePath::removeDuplicates(remoteDirs);
|
FilePath::removeDuplicates(remoteDirs);
|
||||||
|
|
||||||
async.setConcurrentCallData([remoteDirs](QPromise<ResultType> &promise) {
|
async.setConcurrentCallData([remoteDirs](QPromise<Result> &promise) {
|
||||||
for (const FilePath &dir : remoteDirs) {
|
for (const FilePath &dir : remoteDirs) {
|
||||||
const expected_str<void> result = dir.ensureWritableDir();
|
const Result result = dir.ensureWritableDir();
|
||||||
promise.addResult(result);
|
promise.addResult(result);
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.future().cancel();
|
promise.future().cancel();
|
||||||
@@ -98,7 +96,7 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onError = [this](const Async<ResultType> &async) {
|
const auto onError = [this](const Async<Result> &async) {
|
||||||
const int numResults = async.future().resultCount();
|
const int numResults = async.future().resultCount();
|
||||||
if (numResults == 0) {
|
if (numResults == 0) {
|
||||||
addErrorMessage(
|
addErrorMessage(
|
||||||
@@ -107,13 +105,13 @@ GroupItem GenericDeployStep::mkdirTask(const Storage<FilesToTransfer> &storage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numResults; ++i) {
|
for (int i = 0; i < numResults; ++i) {
|
||||||
const ResultType result = async.future().resultAt(i);
|
const Result result = async.future().resultAt(i);
|
||||||
if (!result.has_value())
|
if (!result)
|
||||||
addErrorMessage(result.error());
|
addErrorMessage(result.error());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return AsyncTask<ResultType>(onSetup, onError, CallDoneIf::Error);
|
return AsyncTask<Result>(onSetup, onError, CallDoneIf::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FileTransferMethod effectiveTransferMethodFor(const FileToTransfer &fileToTransfer,
|
static FileTransferMethod effectiveTransferMethodFor(const FileToTransfer &fileToTransfer,
|
||||||
|
@@ -1066,7 +1066,7 @@ LinuxDevice::LinuxDevice()
|
|||||||
});
|
});
|
||||||
|
|
||||||
addDeviceAction({Tr::tr("Open Remote Shell"), [](const IDevice::Ptr &device, QWidget *) {
|
addDeviceAction({Tr::tr("Open Remote Shell"), [](const IDevice::Ptr &device, QWidget *) {
|
||||||
expected_str<void> result = device->openTerminal(Environment(), FilePath());
|
Result result = device->openTerminal(Environment(), FilePath());
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
QMessageBox::warning(nullptr, Tr::tr("Error"), result.error());
|
QMessageBox::warning(nullptr, Tr::tr("Error"), result.error());
|
||||||
@@ -1567,18 +1567,18 @@ private:
|
|||||||
QHash<FilePath, FilesToTransfer> m_batches;
|
QHash<FilePath, FilesToTransfer> m_batches;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void createDir(QPromise<expected_str<void>> &promise, const FilePath &pathToCreate)
|
static void createDir(QPromise<Result> &promise, const FilePath &pathToCreate)
|
||||||
{
|
{
|
||||||
const expected_str<void> result = pathToCreate.ensureWritableDir();
|
const Result result = pathToCreate.ensureWritableDir();
|
||||||
promise.addResult(result);
|
promise.addResult(result);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
promise.future().cancel();
|
promise.future().cancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
static void copyFile(QPromise<expected_str<void>> &promise, const FileToTransfer &file)
|
static void copyFile(QPromise<Result> &promise, const FileToTransfer &file)
|
||||||
{
|
{
|
||||||
const expected_str<void> result = file.m_source.copyFile(file.m_target);
|
const Result result = file.m_source.copyFile(file.m_target);
|
||||||
promise.addResult(result);
|
promise.addResult(result);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -1606,13 +1606,13 @@ private:
|
|||||||
|
|
||||||
const LoopList iteratorParentDirs(QList(allParentDirs.cbegin(), allParentDirs.cend()));
|
const LoopList iteratorParentDirs(QList(allParentDirs.cbegin(), allParentDirs.cend()));
|
||||||
|
|
||||||
const auto onCreateDirSetup = [iteratorParentDirs](Async<expected_str<void>> &async) {
|
const auto onCreateDirSetup = [iteratorParentDirs](Async<Result> &async) {
|
||||||
async.setConcurrentCallData(createDir, *iteratorParentDirs);
|
async.setConcurrentCallData(createDir, *iteratorParentDirs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onCreateDirDone = [this,
|
const auto onCreateDirDone = [this,
|
||||||
iteratorParentDirs](const Async<expected_str<void>> &async) {
|
iteratorParentDirs](const Async<Result> &async) {
|
||||||
const expected_str<void> result = async.result();
|
const Result result = async.result();
|
||||||
if (result)
|
if (result)
|
||||||
emit progress(
|
emit progress(
|
||||||
Tr::tr("Created directory: \"%1\".\n").arg(iteratorParentDirs->toUserOutput()));
|
Tr::tr("Created directory: \"%1\".\n").arg(iteratorParentDirs->toUserOutput()));
|
||||||
@@ -1623,13 +1623,13 @@ private:
|
|||||||
const LoopList iterator(m_setup.m_files);
|
const LoopList iterator(m_setup.m_files);
|
||||||
const Storage<int> counterStorage;
|
const Storage<int> counterStorage;
|
||||||
|
|
||||||
const auto onCopySetup = [iterator](Async<expected_str<void>> &async) {
|
const auto onCopySetup = [iterator](Async<Result> &async) {
|
||||||
async.setConcurrentCallData(copyFile, *iterator);
|
async.setConcurrentCallData(copyFile, *iterator);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onCopyDone = [this, iterator, counterStorage](
|
const auto onCopyDone = [this, iterator, counterStorage](
|
||||||
const Async<expected_str<void>> &async) {
|
const Async<Result> &async) {
|
||||||
const expected_str<void> result = async.result();
|
const Result result = async.result();
|
||||||
int &counter = *counterStorage;
|
int &counter = *counterStorage;
|
||||||
++counter;
|
++counter;
|
||||||
|
|
||||||
@@ -1648,12 +1648,12 @@ private:
|
|||||||
const Group recipe {
|
const Group recipe {
|
||||||
For (iteratorParentDirs) >> Do {
|
For (iteratorParentDirs) >> Do {
|
||||||
parallelIdealThreadCountLimit,
|
parallelIdealThreadCountLimit,
|
||||||
AsyncTask<expected_str<void>>(onCreateDirSetup, onCreateDirDone),
|
AsyncTask<Result>(onCreateDirSetup, onCreateDirDone),
|
||||||
},
|
},
|
||||||
For (iterator) >> Do {
|
For (iterator) >> Do {
|
||||||
parallelLimit(2),
|
parallelLimit(2),
|
||||||
counterStorage,
|
counterStorage,
|
||||||
AsyncTask<expected_str<void>>(onCopySetup, onCopyDone),
|
AsyncTask<Result>(onCopySetup, onCopyDone),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -185,7 +185,7 @@ void SquishTestTreeItemDelegate::setEditorData(QWidget *editor, const QModelInde
|
|||||||
|
|
||||||
static bool copyScriptTemplates(const SuiteConf &suiteConf, const Utils::FilePath &destination)
|
static bool copyScriptTemplates(const SuiteConf &suiteConf, const Utils::FilePath &destination)
|
||||||
{
|
{
|
||||||
Utils::expected_str<void> result = destination.ensureWritableDir();
|
Utils::Result result = destination.ensureWritableDir();
|
||||||
QTC_ASSERT_EXPECTED(result, return false);
|
QTC_ASSERT_EXPECTED(result, return false);
|
||||||
|
|
||||||
const bool scripted = suiteConf.objectMapStyle() == "script";
|
const bool scripted = suiteConf.objectMapStyle() == "script";
|
||||||
|
@@ -323,7 +323,7 @@ bool SuiteConf::ensureObjectMapExists() const
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
const Utils::FilePath objectMap = scripts.pathAppended("objectmap_template" + extension);
|
const Utils::FilePath objectMap = scripts.pathAppended("objectmap_template" + extension);
|
||||||
Utils::expected_str<void> result = destinationObjectMap.parentDir().ensureWritableDir();
|
Utils::Result result = destinationObjectMap.parentDir().ensureWritableDir();
|
||||||
QTC_ASSERT_EXPECTED(result, return false);
|
QTC_ASSERT_EXPECTED(result, return false);
|
||||||
result = objectMap.copyFile(destinationObjectMap);
|
result = objectMap.copyFile(destinationObjectMap);
|
||||||
QTC_ASSERT_EXPECTED(result, return false);
|
QTC_ASSERT_EXPECTED(result, return false);
|
||||||
|
@@ -172,7 +172,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
|
|||||||
const FilePath rcPath = filesToCopy.bash.rcFile;
|
const FilePath rcPath = filesToCopy.bash.rcFile;
|
||||||
const FilePath tmpRc = FilePath::fromUserInput(
|
const FilePath tmpRc = FilePath::fromUserInput(
|
||||||
m_tempDir.filePath(filesToCopy.bash.rcFile.fileName()));
|
m_tempDir.filePath(filesToCopy.bash.rcFile.fileName()));
|
||||||
expected_str<void> copyResult = rcPath.copyFile(tmpRc);
|
const Result copyResult = rcPath.copyFile(tmpRc);
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return);
|
QTC_ASSERT_EXPECTED(copyResult, return);
|
||||||
|
|
||||||
if (cmd.arguments() == "-l")
|
if (cmd.arguments() == "-l")
|
||||||
@@ -181,7 +181,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
|
|||||||
cmd = {cmd.executable(), {"--init-file", tmpRc.nativePath()}};
|
cmd = {cmd.executable(), {"--init-file", tmpRc.nativePath()}};
|
||||||
} else if (cmd.executable().baseName() == "zsh") {
|
} else if (cmd.executable().baseName() == "zsh") {
|
||||||
for (const FileToCopy &file : filesToCopy.zsh.files) {
|
for (const FileToCopy &file : filesToCopy.zsh.files) {
|
||||||
const expected_str<void> copyResult = file.source.copyFile(
|
const Result copyResult = file.source.copyFile(
|
||||||
FilePath::fromUserInput(m_tempDir.filePath(file.destName)));
|
FilePath::fromUserInput(m_tempDir.filePath(file.destName)));
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return);
|
QTC_ASSERT_EXPECTED(copyResult, return);
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
|
|||||||
const FilePath rcPath = filesToCopy.pwsh.script;
|
const FilePath rcPath = filesToCopy.pwsh.script;
|
||||||
const FilePath tmpRc = FilePath::fromUserInput(
|
const FilePath tmpRc = FilePath::fromUserInput(
|
||||||
m_tempDir.filePath(filesToCopy.pwsh.script.fileName()));
|
m_tempDir.filePath(filesToCopy.pwsh.script.fileName()));
|
||||||
expected_str<void> copyResult = rcPath.copyFile(tmpRc);
|
const Result copyResult = rcPath.copyFile(tmpRc);
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return);
|
QTC_ASSERT_EXPECTED(copyResult, return);
|
||||||
|
|
||||||
cmd.addArgs(QString("-noexit -command try { . '%1' } catch {Write-Host \"Shell "
|
cmd.addArgs(QString("-noexit -command try { . '%1' } catch {Write-Host \"Shell "
|
||||||
@@ -207,7 +207,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
|
|||||||
const FilePath rcPath = filesToCopy.clink.script;
|
const FilePath rcPath = filesToCopy.clink.script;
|
||||||
const FilePath tmpRc = FilePath::fromUserInput(
|
const FilePath tmpRc = FilePath::fromUserInput(
|
||||||
m_tempDir.filePath(filesToCopy.clink.script.fileName()));
|
m_tempDir.filePath(filesToCopy.clink.script.fileName()));
|
||||||
expected_str<void> copyResult = rcPath.copyFile(tmpRc);
|
const Result copyResult = rcPath.copyFile(tmpRc);
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return);
|
QTC_ASSERT_EXPECTED(copyResult, return);
|
||||||
|
|
||||||
env.set("CLINK_HISTORY_LABEL", "QtCreator");
|
env.set("CLINK_HISTORY_LABEL", "QtCreator");
|
||||||
@@ -216,7 +216,7 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
|
|||||||
FilePath xdgDir = FilePath::fromUserInput(m_tempDir.filePath("fish_xdg_data"));
|
FilePath xdgDir = FilePath::fromUserInput(m_tempDir.filePath("fish_xdg_data"));
|
||||||
FilePath subDir = xdgDir.resolvePath(QString("fish/vendor_conf.d"));
|
FilePath subDir = xdgDir.resolvePath(QString("fish/vendor_conf.d"));
|
||||||
QTC_ASSERT(subDir.createDir(), return);
|
QTC_ASSERT(subDir.createDir(), return);
|
||||||
expected_str<void> copyResult = filesToCopy.fish.script.copyFile(
|
const Result copyResult = filesToCopy.fish.script.copyFile(
|
||||||
subDir.resolvePath(filesToCopy.fish.script.fileName()));
|
subDir.resolvePath(filesToCopy.fish.script.fileName()));
|
||||||
QTC_ASSERT_EXPECTED(copyResult, return);
|
QTC_ASSERT_EXPECTED(copyResult, return);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user