~ubuntu-branches/ubuntu/oneiric/partitionmanager/oneiric

« back to all changes in this revision

Viewing changes to src/jobs/backupfilesystemjob.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-23 17:57:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090123175736-2ltrhgg3m55dokbm
Tags: upstream-1.0.0~beta1a
ImportĀ upstreamĀ versionĀ 1.0.0~beta1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Volker Lanz <vl@fidra.de>                       *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 
18
 ***************************************************************************/
 
19
 
 
20
#include "jobs/backupfilesystemjob.h"
 
21
 
 
22
#include "core/partition.h"
 
23
#include "core/device.h"
 
24
#include "core/copysourcedevice.h"
 
25
#include "core/copytargetfile.h"
 
26
 
 
27
#include "fs/filesystem.h"
 
28
 
 
29
#include "util/report.h"
 
30
 
 
31
#include <klocale.h>
 
32
 
 
33
/** Creates a new BackupFileSystemJob
 
34
        @param sourcedevice the device the FileSystem to back up is on
 
35
        @param sourcepartition the Partition the FileSystem to back up is on
 
36
        @param filename name of the file to backup to
 
37
*/
 
38
BackupFileSystemJob::BackupFileSystemJob(Device& sourcedevice, Partition& sourcepartition, const QString& filename) :
 
39
        Job(),
 
40
        m_SourceDevice(sourcedevice),
 
41
        m_SourcePartition(sourcepartition),
 
42
        m_FileName(filename)
 
43
{
 
44
}
 
45
 
 
46
qint32 BackupFileSystemJob::numSteps() const
 
47
{
 
48
        return 100;
 
49
}
 
50
 
 
51
bool BackupFileSystemJob::run(Report& parent)
 
52
{
 
53
        bool rval = false;
 
54
        
 
55
        Report* report = jobStarted(parent);
 
56
        
 
57
        if (sourcePartition().fileSystem().supportBackup() == FileSystem::SupportExternal)
 
58
                rval = sourcePartition().fileSystem().backup(*report, sourceDevice(), sourcePartition().deviceNode(), fileName());
 
59
        else if (sourcePartition().fileSystem().supportBackup() == FileSystem::SupportInternal)
 
60
        {
 
61
                CopySourceDevice copySource(sourceDevice(), sourcePartition().fileSystem().firstSector(), sourcePartition().fileSystem().lastSector());
 
62
                CopyTargetFile copyTarget(fileName(), sourceDevice().sectorSize());
 
63
 
 
64
                if (!copySource.open())
 
65
                        report->line() << i18nc("@info/plain", "Could not open file system on source partition <filename>%1</filename> for backup.", sourcePartition().deviceNode());
 
66
                else if (!copyTarget.open())
 
67
                        report->line() << i18nc("@info/plain", "Could not create backup file <filename>%1</filename>.", fileName());
 
68
                else
 
69
                        rval = copyBlocks(*report, copyTarget, copySource);
 
70
        }
 
71
        
 
72
        jobFinished(*report, rval);
 
73
 
 
74
        return rval;
 
75
}
 
76
 
 
77
QString BackupFileSystemJob::description() const
 
78
{
 
79
        return i18nc("@info/plain", "Back up file system on partition <filename>%1</filename> to <filename>%2</filename>", sourcePartition().deviceNode(), fileName());
 
80
}