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