2020-09-29 23:55:11 +01:00
/*
SPDX - FileCopyrightText : 2008 - 2010 Volker Lanz < vl @ fidra . de >
SPDX - FileCopyrightText : 2014 - 2018 Andrius Š tikonas < andrius @ stikonas . eu >
SPDX - FileCopyrightText : 2016 Chantara Tith < tith . chantara @ gmail . com >
SPDX - FileCopyrightText : 2018 Huzaifa Faruqui < huzaifafaruqui @ gmail . com >
SPDX - License - Identifier : GPL - 3.0 - or - later
*/
2015-06-04 01:29:22 +01:00
# include "jobs/backupfilesystemjob.h"
# include "core/partition.h"
# include "core/device.h"
# include "core/copysourcedevice.h"
# include "core/copytargetfile.h"
# include "fs/filesystem.h"
2018-01-24 15:22:42 +00:00
# include "util/externalcommand.h"
2015-06-04 01:29:22 +01:00
# include "util/report.h"
# include <KLocalizedString>
/** Creates a new BackupFileSystemJob
2015-07-13 15:16:36 +01:00
@ param sourcedevice the device the FileSystem to back up is on
@ param sourcepartition the Partition the FileSystem to back up is on
@ param filename name of the file to backup to
2015-06-04 01:29:22 +01:00
*/
BackupFileSystemJob : : BackupFileSystemJob ( Device & sourcedevice , Partition & sourcepartition , const QString & filename ) :
2015-07-13 15:16:36 +01:00
Job ( ) ,
m_SourceDevice ( sourcedevice ) ,
m_SourcePartition ( sourcepartition ) ,
m_FileName ( filename )
2015-06-04 01:29:22 +01:00
{
}
qint32 BackupFileSystemJob : : numSteps ( ) const
{
2015-07-13 15:16:36 +01:00
return 100 ;
2015-06-04 01:29:22 +01:00
}
bool BackupFileSystemJob : : run ( Report & parent )
{
2015-07-13 15:16:36 +01:00
bool rval = false ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
Report * report = jobStarted ( parent ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
if ( sourcePartition ( ) . fileSystem ( ) . supportBackup ( ) = = FileSystem : : cmdSupportFileSystem )
rval = sourcePartition ( ) . fileSystem ( ) . backup ( * report , sourceDevice ( ) , sourcePartition ( ) . deviceNode ( ) , fileName ( ) ) ;
else if ( sourcePartition ( ) . fileSystem ( ) . supportBackup ( ) = = FileSystem : : cmdSupportCore ) {
2017-10-26 16:20:21 +01:00
CopySourceDevice copySource ( sourceDevice ( ) , sourcePartition ( ) . fileSystem ( ) . firstByte ( ) , sourcePartition ( ) . fileSystem ( ) . lastByte ( ) ) ;
CopyTargetFile copyTarget ( fileName ( ) ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
if ( ! copySource . open ( ) )
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Could not open file system on source partition <filename>%1</filename> for backup. " , sourcePartition ( ) . deviceNode ( ) ) ;
2015-07-13 15:16:36 +01:00
else if ( ! copyTarget . open ( ) )
2016-07-17 23:41:00 +01:00
report - > line ( ) < < xi18nc ( " @info:progress " , " Could not create backup file <filename>%1</filename>. " , fileName ( ) ) ;
2018-01-24 15:45:19 +00:00
else
rval = copyBlocks ( * report , copyTarget , copySource ) ;
2015-07-13 15:16:36 +01:00
}
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
jobFinished ( * report , rval ) ;
2015-06-04 01:29:22 +01:00
2015-07-13 15:16:36 +01:00
return rval ;
2015-06-04 01:29:22 +01:00
}
QString BackupFileSystemJob : : description ( ) const
{
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:progress " , " Back up file system on partition <filename>%1</filename> to <filename>%2</filename> " , sourcePartition ( ) . deviceNode ( ) , fileName ( ) ) ;
2015-06-04 01:29:22 +01:00
}