diff options
author | Tim Jenssen <tim.jenssen@nokia.com> | 2012-05-24 15:51:00 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@nokia.com> | 2012-05-25 09:03:36 +0200 |
commit | fb396036ccf3a0fd75d57c68e1e301b291245371 (patch) | |
tree | 4dbb1baedece7eda5ec2655a48380ce3f402dc1b /src/libs/installer/createlinkoperation.cpp | |
parent | 4fc262a5bd06ceae38fa33e2a7993937a43fe139 (diff) |
added new Link class and corresponding operation
- replace read junction link target code with already existing Qt code
Change-Id: I6642f19ceb9a907791987ced8e9eacc6ca4f2780
Reviewed-by: Karsten Heimrich <karsten.heimrich@nokia.com>
Diffstat (limited to 'src/libs/installer/createlinkoperation.cpp')
-rw-r--r-- | src/libs/installer/createlinkoperation.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/libs/installer/createlinkoperation.cpp b/src/libs/installer/createlinkoperation.cpp new file mode 100644 index 000000000..b844e179b --- /dev/null +++ b/src/libs/installer/createlinkoperation.cpp @@ -0,0 +1,105 @@ +/************************************************************************** +** +** This file is part of Installer Framework +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ +#include "createlinkoperation.h" + +#include "link.h" + +#include <QFileInfo> + +using namespace QInstaller; + +/* +TRANSLATOR QInstaller::CreateLinkOperation +*/ + +CreateLinkOperation::CreateLinkOperation() +{ + setName(QLatin1String("CreateLink")); +} + +void CreateLinkOperation::backup() +{ +} + +bool CreateLinkOperation::performOperation() +{ + QStringList args = arguments(); + + if (args.count() != 2) { + setError(InvalidArguments); + setErrorString(QObject::tr("Invalid arguments: %1 arguments given, 2 expected").arg( + args.count())); + return false; + } + + const QString& linkPath = args.at(0); + const QString& targetPath = args.at(1); + Link link = Link::create(linkPath, targetPath); + + if (!link.isValid()) { + setError(UserDefinedError); + setErrorString(QObject::tr("Could not create link from %1 to %2.").arg(linkPath, targetPath)); + return false; + } + + return true; +} + +bool CreateLinkOperation::undoOperation() +{ + QStringList args = arguments(); + + const QString& linkPath = args.at(0); + const QString& targetPath = args.at(1); + + if (!QFileInfo(linkPath).exists()) { + return true; + } + Link link = Link(linkPath); + if (!link.remove()) { + setError(UserDefinedError); + setErrorString(QObject::tr("Could not remove link from %1 to %2.").arg(linkPath, targetPath)); + return false; + } + + return !QFileInfo(linkPath).exists(); +} + +bool CreateLinkOperation::testOperation() +{ + return true; +} + +Operation *CreateLinkOperation::clone() const +{ + return new CreateLinkOperation(); +} |