Do not use KConfig for the shred action.
This commit is contained in:
parent
eb1879774f
commit
fd8603f70c
|
@ -23,11 +23,11 @@
|
|||
@param s the size the copy source will (pretend to) have
|
||||
@param sectorsize the sectorsize the copy source will (pretend to) have
|
||||
*/
|
||||
CopySourceShred::CopySourceShred (qint64 s, qint32 sectorsize) :
|
||||
CopySourceShred::CopySourceShred (qint64 s, qint32 sectorsize, bool randomShred) :
|
||||
CopySource(),
|
||||
m_Size(s),
|
||||
m_SectorSize(sectorsize),
|
||||
m_SourceFile(Config::shredSource() == Config::EnumShredSource::random ? QStringLiteral("/dev/urandom") : QStringLiteral("/dev/zero"))
|
||||
m_SourceFile(randomShred ? QStringLiteral("/dev/urandom") : QStringLiteral("/dev/zero"))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class CopyTarget;
|
|||
class CopySourceShred : public CopySource
|
||||
{
|
||||
public:
|
||||
CopySourceShred(qint64 size, qint32 sectorsize);
|
||||
CopySourceShred(qint64 size, qint32 sectorsize, bool randomShred);
|
||||
|
||||
public:
|
||||
virtual bool open();
|
||||
|
|
|
@ -35,10 +35,11 @@
|
|||
@param d the Device the FileSystem is on
|
||||
@param p the Partition the FileSystem is in
|
||||
*/
|
||||
ShredFileSystemJob::ShredFileSystemJob(Device& d, Partition& p) :
|
||||
ShredFileSystemJob::ShredFileSystemJob(Device& d, Partition& p, bool randomShred) :
|
||||
Job(),
|
||||
m_Device(d),
|
||||
m_Partition(p)
|
||||
m_Partition(p),
|
||||
m_RandomShred(randomShred)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,7 @@ bool ShredFileSystemJob::run(Report& parent)
|
|||
// Again, a scope for copyTarget and copySource. See MoveFileSystemJob::run()
|
||||
{
|
||||
CopyTargetDevice copyTarget(device(), partition().fileSystem().firstSector(), partition().fileSystem().lastSector());
|
||||
CopySourceShred copySource(partition().capacity(), copyTarget.sectorSize());
|
||||
CopySourceShred copySource(partition().capacity(), copyTarget.sectorSize(), m_RandomShred);
|
||||
|
||||
if (!copySource.open())
|
||||
report->line() << i18nc("@info/plain", "Could not open random data source to overwrite file system.");
|
||||
|
|
|
@ -36,7 +36,7 @@ class Report;
|
|||
class ShredFileSystemJob : public Job
|
||||
{
|
||||
public:
|
||||
ShredFileSystemJob(Device& d, Partition& p);
|
||||
ShredFileSystemJob(Device& d, Partition& p, bool randomShred);
|
||||
|
||||
public:
|
||||
virtual bool run(Report& parent);
|
||||
|
@ -53,6 +53,7 @@ class ShredFileSystemJob : public Job
|
|||
private:
|
||||
Device& m_Device;
|
||||
Partition& m_Partition;
|
||||
bool m_RandomShred;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,16 +35,23 @@
|
|||
@param d the Device to delete a Partition on
|
||||
@param p pointer to the Partition to delete. May not be NULL
|
||||
*/
|
||||
DeleteOperation::DeleteOperation(Device& d, Partition* p, bool secure) :
|
||||
DeleteOperation::DeleteOperation(Device& d, Partition* p, ShredAction shred) :
|
||||
Operation(),
|
||||
m_TargetDevice(d),
|
||||
m_DeletedPartition(p),
|
||||
m_Secure(secure),
|
||||
m_DeleteFileSystemJob(isSecure()
|
||||
? static_cast<Job*>(new ShredFileSystemJob(targetDevice(), deletedPartition()))
|
||||
: static_cast<Job*>(new DeleteFileSystemJob(targetDevice(), deletedPartition()))),
|
||||
m_ShredAction(shred),
|
||||
m_DeletePartitionJob(new DeletePartitionJob(targetDevice(), deletedPartition()))
|
||||
{
|
||||
switch(shredAction())
|
||||
{
|
||||
case NoShred:
|
||||
m_DeleteFileSystemJob = static_cast<Job*>(new DeleteFileSystemJob(targetDevice(), deletedPartition()));
|
||||
case ZeroShred:
|
||||
m_DeleteFileSystemJob = static_cast<Job*>(new ShredFileSystemJob(targetDevice(), deletedPartition(), false));
|
||||
case RandomShred:
|
||||
m_DeleteFileSystemJob = static_cast<Job*>(new ShredFileSystemJob(targetDevice(), deletedPartition(), true));
|
||||
}
|
||||
|
||||
addJob(deleteFileSystemJob());
|
||||
addJob(deletePartitionJob());
|
||||
}
|
||||
|
@ -79,7 +86,7 @@ void DeleteOperation::undo()
|
|||
|
||||
QString DeleteOperation::description() const
|
||||
{
|
||||
if (isSecure())
|
||||
if (shredAction() != NoShred)
|
||||
return xi18nc("@info/plain", "Shred partition <filename>%1</filename> (%2, %3)", deletedPartition().deviceNode(), Capacity::formatByteSize(deletedPartition().capacity()), deletedPartition().fileSystem().name());
|
||||
else
|
||||
return xi18nc("@info/plain", "Delete partition <filename>%1</filename> (%2, %3)", deletedPartition().deviceNode(), Capacity::formatByteSize(deletedPartition().capacity()), deletedPartition().fileSystem().name());
|
||||
|
|
|
@ -43,15 +43,24 @@ class LIBKPMCORE_EXPORT DeleteOperation : public Operation
|
|||
Q_DISABLE_COPY(DeleteOperation)
|
||||
|
||||
public:
|
||||
DeleteOperation(Device& d, Partition* p, bool secure = false);
|
||||
enum ShredAction
|
||||
{
|
||||
NoShred = 0,
|
||||
ZeroShred,
|
||||
RandomShred
|
||||
};
|
||||
|
||||
DeleteOperation(Device& d, Partition* p, ShredAction shred = NoShred);
|
||||
~DeleteOperation();
|
||||
|
||||
public:
|
||||
QString iconName() const { return isSecure() ? QStringLiteral("edit-delete-shred") : QStringLiteral("edit-delete"); }
|
||||
QString iconName() const { return shredAction() == NoShred ?
|
||||
QStringLiteral("edit-delete") :
|
||||
QStringLiteral("edit-delete-shred"); }
|
||||
QString description() const;
|
||||
void preview();
|
||||
void undo();
|
||||
bool isSecure() const { return m_Secure; }
|
||||
ShredAction shredAction() const { return m_ShredAction; }
|
||||
|
||||
virtual bool targets(const Device& d) const;
|
||||
virtual bool targets(const Partition& p) const;
|
||||
|
@ -75,7 +84,7 @@ class LIBKPMCORE_EXPORT DeleteOperation : public Operation
|
|||
private:
|
||||
Device& m_TargetDevice;
|
||||
Partition* m_DeletedPartition;
|
||||
bool m_Secure;
|
||||
ShredAction m_ShredAction;
|
||||
Job* m_DeleteFileSystemJob;
|
||||
DeletePartitionJob* m_DeletePartitionJob;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue